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;
}
相关推荐
steins_甲乙14 小时前
C++并发编程
开发语言·c++
南莺莺15 小时前
二叉排序树的创建和基本操作---C++实现
数据结构·c++·算法··二叉排序树
仰泳的熊猫15 小时前
1061 Dating
数据结构·c++·算法·pat考试
Fcy64815 小时前
二叉搜索树(C++实现)
开发语言·数据结构·c++·二叉搜索树
surtr115 小时前
Round 1019(div2) CD
数据结构·c++·算法·贪心算法·stl
Tim_1015 小时前
【C++入门】02、C++程序初识
开发语言·c++
小小晓.16 小时前
Pinely Round 2 (Div. 1 + Div. 2)
c++·算法
清风拂山岗 明月照大江16 小时前
简单文件 IO 示例:使用系统调用读写文件
开发语言·c++·算法
学困昇16 小时前
Linux基础开发工具(下):调试器gdb/cgdb的使用详解
linux·运维·服务器·开发语言·c++