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;
}
相关推荐
沫璃染墨3 小时前
《从零入门Linux系统篇(五十一):线程篇·四——pthread线程库详解:从线程创建到终止与分离》
linux·运维·服务器·开发语言·c++·系统架构·线程
shada3 小时前
CMake指定 MSVC 工具集与 Windows SDK
c++·windows
垆边人似月.4 小时前
华为机考题:矩阵中的最长递增路径
c语言·c++
A7bert7774 小时前
【SAM3部署至AGX Orin】环境配置→模型部署→问题记录
c++·人工智能·深度学习·ubuntu
longlongzihan4 小时前
LeetCode 56合并区间:排序与贪心
c++·算法·leetcode
程序员老陆4 小时前
C++ 继承方式:公有、保护、私有,到底在控制什么
开发语言·c++
坤坤子吖4 小时前
C++11——Lambda、function、bind 与可调用对象
c++·笔记·学习
白杨尚青5 小时前
C++入门篇(十一):string(中)——容量与增删改查:一篇吃透所有常用接口(万字详解)
java·开发语言·c++
朔北之忘 Clancy5 小时前
2024 CSP-J 第二轮真题解析
c++·算法·青少年编程·noip·csp·信奥赛·noi
Lazionr5 小时前
set和map的使用——从基础接口到实际应用
c++