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;
}
相关推荐
xcyxiner1 小时前
snmp wireshark 抓包
c++
rocksun1 小时前
BJARNE STROUSTRUP谈C++的演变
c++
我不是代码教父1 小时前
[原创](Modern C++)现代C++的关键性概念: 非常独特的std::sentinel_for概念(哨兵概念)
开发语言·c++·sentinel
JuicyActiveGilbert1 小时前
【C++设计模式】第十六篇:迭代器模式(Iterator)
c++·设计模式·迭代器模式
commonbelive2 小时前
考研机试常见基本题型
c语言·c++·算法
希望_睿智2 小时前
C++网络编程之套接字选项配置
c++·网络协议
情深不寿3172 小时前
数据结构--AVL树
数据结构·c++
LuckyRich12 小时前
【高并发内存池】释放内存 + 申请和释放总结
开发语言·c++·缓存
明月看潮生3 小时前
青少年编程与数学 02-010 C++程序设计基础 29课题、继承
开发语言·c++·青少年编程·编程与数学
lucky1_1star3 小时前
FX-C++结构体与类的区别
开发语言·c++