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;
}
相关推荐
愚润求学2 分钟前
【C++】类型转换
开发语言·c++
@我漫长的孤独流浪10 分钟前
数据结构测试模拟题(4)
数据结构·c++·算法
csdnzzt28 分钟前
从内存角度透视现代C++关键特性
c++
jie188945758661 小时前
C++ 中的 const 知识点详解,c++和c语言区别
java·c语言·c++
明月*清风1 小时前
c++ —— 内存管理
开发语言·c++
西北大程序猿2 小时前
单例模式与锁(死锁)
linux·开发语言·c++·单例模式
qq_454175792 小时前
c++学习-this指针
开发语言·c++·学习
超闻逸事4 小时前
【题解】[UTPC2024] C.Card Deck
c++·算法
暴力求解4 小时前
C++类和对象(上)
开发语言·c++·算法
让我们一起加油好吗4 小时前
【基础算法】枚举(普通枚举、二进制枚举)
开发语言·c++·算法·二进制·枚举·位运算