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;
}
相关推荐
Cinema KI39 分钟前
内存管理这一块
c++
1白天的黑夜11 小时前
哈希表-49.字母异位词分组-力扣(LeetCode)
c++·leetcode·哈希表
深耕AI1 小时前
【MFC典型类和函数:CString的字符串魔法与Afx全局函数的便利店】
c++·mfc
怀旧,1 小时前
【C++】19. 封装红⿊树实现set和map
linux·c++·算法
凯子坚持 c2 小时前
Redis核心通用命令深度解析:结合C++ redis-plus-plus 实战指南
c++·redis·log4j
神里流~霜灭2 小时前
(C++)数据结构初阶(顺序表的实现)
linux·c语言·数据结构·c++·算法·顺序表·单链表
John_ToDebug2 小时前
从源码视角全面解析 Chrome UI 布局系统及 Views 框架的定制化实现方法与实践经验
c++·chrome·架构
愚润求学2 小时前
【贪心算法】day7
c++·算法·leetcode·贪心算法
深耕AI3 小时前
【MFC简介:从基础概念到实际应用】
c++·mfc
六点半8883 小时前
【C++】C++11 篇二
开发语言·c++