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;
}
相关推荐
hz_zhangrl25 分钟前
CCF-GESP 等级考试 2026年3月认证C++三级真题解析
c++·算法·程序设计·gesp·gesp2026年3月·gesp c++三级
kyle~1 小时前
C++----函数指针与函数指针类型 返回值类型 (*类型名)(参数列表)
开发语言·c++
努力中的编程者1 小时前
二叉树(C语言底层实现)
c语言·开发语言·数据结构·c++·算法
qq_416018722 小时前
高性能密码学库
开发语言·c++·算法
宵时待雨2 小时前
C++笔记归纳14:AVL树
开发语言·数据结构·c++·笔记·算法
呜喵王阿尔萨斯2 小时前
C and C++ code
c语言·开发语言·c++
旺仔.2912 小时前
顺序容器:deque双端队列 详解
c++
Jasonakeke3 小时前
我的编程来时路
java·c++·python
IT从业者张某某3 小时前
基于DEVC++实现一个控制台的赛车游戏-02-实现赛车游戏
开发语言·c++·游戏
2501_908329853 小时前
C++中的备忘录模式
开发语言·c++·算法