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;
}
相关推荐
BizzZ_29 分钟前
C++(22)——类型转换和IO流
开发语言·c++
青梅味猪大肠3 小时前
【深入浅出C++】为什么虚表指针可以解决菱形继承
开发语言·c++
Lhan.zzZ4 小时前
QML 组件库:VS2022 + Qt 静态库方案
开发语言·c++·qt·visual studio
一木 之林6 小时前
五、C++ 新特性、关键字与编译原理(进阶)(二)
java·开发语言·c++
OPEN-F7 小时前
C++11/14新特性精讲:移动语义与智能指针实战
开发语言·c++·算法
闭月之泪舞7 小时前
C++编程学习
c++·学习
哭泣方源炼蛊8 小时前
并查集进阶 P1(带权并查集,并查集分类)
数据结构·c++·算法·二进制·带权并查集
小小龙学IT10 小时前
ONNX Runtime 开源 AI 推理引擎深度解析:从模型部署到边缘 AI 加速的全栈实战
c++·人工智能·开源
五_谷_丰_登10 小时前
平衡二叉树(AVL)讲解二
数据结构·c++
知无不研10 小时前
std::function在使用时遇到的问题
c++·算法·st·function