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;
}
相关推荐
aqiu11111128 分钟前
【C++算法打怪专栏】C++ `unordered_set` 常用初始化与插入方法总结
开发语言·c++·算法
Terra.K43 分钟前
高精度阶乘求和模板深度解析
开发语言·c++·算法
智码看视界1 小时前
C++智能指针全景剖析及面试20问
开发语言·c++·深度学习·面试·内存管理·智能指针
Peregrine92 小时前
C++ - > 类和对象
java·c++·算法
‎ദ്ദിᵔ.˛.ᵔ₎3 小时前
c++11:fuction包装器
开发语言·c++
霍霍的袁4 小时前
【C++】哈希表实现指南:从原理到开放定址法、链地址法的实现
c++·学习·哈希算法·散列表·visual studio
WL学习笔记5 小时前
类和对象(下)
c++·类和对象
傲世仙尊5 小时前
拷贝构造-传值传参的连锁反应与隐式函数的三个局限
c++
垆边人似月.6 小时前
华为机试题 :最大数
c++·算法·华为
方便面不加香菜6 小时前
C++ 关于多态的知识点讲解
开发语言·c++