10391 - Compound Words (UVA)

题目链接如下:

Online Judge

代码如下:

cpp 复制代码
#include <iostream>
#include <string>
#include <vector>
#include <set>
// #define debug

int main(){
    #ifdef debug
    freopen("0.txt", "r", stdin);
    freopen("1.txt", "w", stdout);
    #endif
    std::string word;
    std::vector<std::string> vec;
    std::set<std::string> st;
    while (std::cin >> word){
        vec.push_back(word);
        st.insert(word);
    }
    for (int i = 0; i < vec.size(); ++i){
        for (int j = 1; j < vec[i].size(); ++j){
            if(st.count(vec[i].substr(0, j)) && st.count(vec[i].substr(j))){
                std::cout << vec[i] << std::endl;
                break;
            }
        }
    }
    #ifdef debug
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}
相关推荐
INGNIGHT7 分钟前
单词搜索 II · Word Search II
数据结构·c++·算法
楼田莉子20 分钟前
C++学习:C++11关于类型的处理
开发语言·c++·后端·学习
彷徨而立1 小时前
【C/C++】只知道窗口句柄,如何擦除窗口内容,清理窗口?
c语言·c++·windows
強云1 小时前
匿名命名空间 - c++
c++
云知谷2 小时前
【经典书籍】C++ Primer 第14类虚函数与多态精华讲解
c语言·开发语言·c++·软件工程·团队开发
HVACoder2 小时前
复习下线性代数,使用向量平移拼接两段线
c++·线性代数·算法
电子云与长程纠缠2 小时前
UE5 C++ CVar控制台命令字段使用
c++·学习·ue5
一匹电信狗3 小时前
【C++】手搓AVL树
服务器·c++·算法·leetcode·小程序·stl·visual studio
秋空樱雨3 小时前
C++入门
开发语言·c++
咬_咬3 小时前
C++仿mudo库高并发服务器项目:Buffer模块
服务器·开发语言·c++·缓冲区·buffer·muduo库