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;
}
相关推荐
WL学习笔记2 小时前
vector模拟实现
c++
蜗牛一步步往上爬5 小时前
第十六章 C++语言在深度学习中的应用
开发语言·c++·深度学习
wo_jack8 小时前
C++ 入门笔记(十六):第16课 vector 模拟实现十问十答 —— 从三指针到迭代器失效
c++·后端·面试·stl·vector
D e re k ZH9 小时前
C++ 标准库算法全景指南
数据结构·c++·算法
雪落漂泊10 小时前
C++算法 二分查找篇(上)
开发语言·c++·算法
不会算法的笨小孩11 小时前
异常的使用以及会出现的问题
开发语言·c++·c++11·异常
Hhy_110713 小时前
《C++深度解构06》手撕 string —— 从底层内存管理到深浅拷贝彻底吃透
c语言·开发语言·c++·学习·visual studio
青少儿编程课堂14 小时前
蓝桥杯青少组图形化省考报名倒计时·全国青少年信息素养大赛·电子学会图形化考级:校园黑白棋人机对战解析
c++·python·算法·bfs·信息学竞赛
YSL07012414 小时前
C++基础
开发语言·c++
eggwyw15 小时前
关于C++为什么不加入垃圾回收机制解析
开发语言·c++