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;
}
相关推荐
知识领航员4 小时前
蘑兔AI音乐深度实测:功能拆解、实测表现与适用场景
java·c语言·c++·人工智能·python·算法·github
jf加菲猫6 小时前
第21章 Qt WebEngine
开发语言·c++·qt·ui
码农-阿杰6 小时前
深入理解 synchronized 底层实现:从 HotSpot C++ 源码看对象锁与 Monitor 机制
开发语言·c++·
Szime7 小时前
深智微IC华润微代理:MCU选型与工业控制方案推荐
c++
叼烟扛炮7 小时前
C++ 知识点18 内部类
开发语言·c++·算法·内部类
汉克老师7 小时前
GESP5级C++考试语法知识(十五、分治算法(二))
c++·算法·排序算法·分治算法·gesp5级·gesp五级
汉克老师8 小时前
GESP6级C++考试语法知识(五、格雷码)
c++·算法·位运算·异或·gesp6级·gesp六级·格雷码
程序leo源9 小时前
C语言知识总结
c语言·开发语言·c++·经验分享·笔记·青少年编程·c#
沫璃染墨9 小时前
二叉搜索树完全指南:从核心原理到增删查改全实现
开发语言·c++
‎ദ്ദിᵔ.˛.ᵔ₎9 小时前
C++哈希表
数据结构·c++·散列表