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;
}
相关推荐
sulikey3 分钟前
C++ 四十年:一段跨越时代的语言旅程
c++·c++40周年
-森屿安年-28 分钟前
LeetCode 283. 移动零
开发语言·c++·算法·leetcode
散峰而望1 小时前
C++数组(一)(算法竞赛)
c语言·开发语言·c++·算法·github
FuckPatience4 小时前
C++ 常用类型写法和全称
开发语言·c++
__BMGT()4 小时前
参考文章资源记录
开发语言·c++·qt
ouliten4 小时前
C++笔记:std::string_view
开发语言·c++·笔记
玫瑰花店5 小时前
万字C++中锁机制和内存序详解
开发语言·c++·算法
D_evil__5 小时前
[C++高频精进] 文件IO:文件流
c++
西幻凌云5 小时前
认识STL序列式容器——List
开发语言·c++·stl·list·序列式容器
Elias不吃糖6 小时前
LeetCode每日一练(209, 167)
数据结构·c++·算法·leetcode