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;
}
相关推荐
eggwyw6 小时前
C++ union 的一种妙用法
开发语言·c++
ShineWinsu7 小时前
对于Qt:QHBoxLayout常见属性以及方法的解析
c++·qt·面试·gui·客户端·布局管理器·水平布局器
小七在进步9 小时前
string的实现(1)
c++·笔记·visual studio
敲上瘾11 小时前
Qt核心机制:信号与槽详解
开发语言·c++·qt·ui·qt6.3
牢姐与蒯12 小时前
cpp算法之哈希
c++·算法·哈希算法
lcj251113 小时前
[C++] C++11
开发语言·c++·笔记
小小bugbug16 小时前
带工作窃取的线程池
c++·线程池
南风84111 天前
C++ 四种强制类型转换详解
c++
微笑星河q1 天前
C++STL【vector】常用接口函数使用和迭代器失效问题
开发语言·c++
HaiXCoder2 天前
C++ 表达式怎么读:从一行代码到类型、值类别和生命周期
c++