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;
}
相关推荐
f狐0狸x11 分钟前
【C++修炼之路】C++继承的探索
c++·继承
虚无的纽扣16 分钟前
【C++】C++11的魔法:不止右值引用,C++11赋予的编程神力
c++
码匠许师傅1 小时前
【C++三方组件】RE2:工业级正则的安全与性能
c++
ThornArmor1 小时前
《向内深潜,向外飞掠》
c语言·开发语言·c++·vim·visual studio
j7~1 小时前
【C++微服务项目开发脚手架】(环境篇)虚拟机 + Docker + MySQL/Redis/RabbitMQ/ES/etcd/FastDFS 全套配齐
linux·c++·ubuntu·docker·vmware·项目开发·微服务脚手架
qq_199886871 小时前
第5板块·第4节:性能优化中的高级技巧
c++·人工智能·gpu算力
郝学胜_神的一滴1 小时前
C++20模板元编程 04:变量模板 别名模板与模板Lambda实战
c++·visual studio
Methy1 小时前
一次线上死锁排查:std::list::size () 居然是 O (n)?
c++·后端
2401_868534781 小时前
利弊比较类 社会生活类
c++·需求分析
wuminyu2 小时前
纯轻量级锁体系下C2编译器锁粗化和消除机制剖析
java·linux·c语言·jvm·c++