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;
}
相关推荐
-dzk-8 小时前
【代码随想录】LC 59.螺旋矩阵 II
c++·线性代数·算法·矩阵·模拟
m0_706653239 小时前
C++编译期数组操作
开发语言·c++·算法
qq_423233909 小时前
C++与Python混合编程实战
开发语言·c++·算法
m0_715575349 小时前
分布式任务调度系统
开发语言·c++·算法
CSDN_RTKLIB9 小时前
简化版unique_ptr说明其本质
c++
naruto_lnq9 小时前
泛型编程与STL设计思想
开发语言·c++·算法
m0_7487080510 小时前
C++中的观察者模式实战
开发语言·c++·算法
时光找茬11 小时前
【瑞萨AI挑战赛-FPB-RA6E2】+ 从零开始:FPB-RA6E2 开箱测评与 e2 studio 环境配置
c++·单片机·边缘计算
qq_5375626711 小时前
跨语言调用C++接口
开发语言·c++·算法
猷咪11 小时前
C++基础
开发语言·c++