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;
}
相关推荐
XH华8 分钟前
C++语言第二章类和对象(下)
开发语言·c++
从零开始的代码生活_19 分钟前
C++ stack、queue 与 priority_queue:容器适配器原理与实战
开发语言·c++·后端·学习·算法
AA陈超2 小时前
003 XiYou 西游 — P0 阶段实施计划
c++·笔记·学习·ue5
黑不溜秋的2 小时前
C++ STL 容器使用的底层数据结构
c++
灵晔君2 小时前
【C++】标准模板库STL——set /multiset/map /multimap
开发语言·c++
noipp3 小时前
推荐题目:洛谷 P13554 【MX-X15-T1】奶龙龙
c语言·数据结构·c++·算法·编程·洛谷
库玛西4 小时前
深入剖析 Linux 线程机制与分页式存储管理
linux·服务器·c++·笔记
众少成多积小致巨5 小时前
Android C++ 编码规范指南
android·c++·google
Yyyyyy~5 小时前
【C++】字符串
c++
wWYy.5 小时前
Pimpl模式
c++