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;
}
相关推荐
Irissgwe18 小时前
类与对象(三)
开发语言·c++·类和对象·友元
️是7818 小时前
信息奥赛一本通—编程启蒙(3395:练68.3 车牌问题)
数据结构·c++·算法
计算机安禾19 小时前
【c++面向对象编程】第24篇:类型转换运算符:自定义隐式转换与explicit
java·c++·算法
雪度娃娃19 小时前
转向现代C++——优先选用nullptr而不是0和NULL
开发语言·c++
我星期八休息19 小时前
Linux系统编程—基础IO
linux·运维·服务器·c语言·c++·人工智能·算法
故事和你9120 小时前
洛谷-【图论2-1】树5
开发语言·数据结构·c++·算法·动态规划·图论
paeamecium20 小时前
【PAT甲级真题】- String Subtraction (20)
数据结构·c++·算法·pat考试·pat
计算机安禾21 小时前
【c++面向对象编程】第25篇:仿函数(函数对象):重载operator()
开发语言·c++·算法
周末也要写八哥1 天前
在C++中使用预定义宏
开发语言·c++·算法
小小编程路1 天前
新手快速学 Python 极简速成指南
开发语言·c++·python