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;
}
相关推荐
西幻凌云5 分钟前
初始——正则表达式
c++·正则表达式·1024程序员节
沧澜sincerely28 分钟前
蓝桥杯101 拉马车
c++·蓝桥杯·stl
w-w0w-w1 小时前
运算符重载
c++
持梦远方2 小时前
持梦行文本编辑器(cmyfEdit):架构设计与十大核心功能实现详解
开发语言·数据结构·c++·算法·microsoft·visual studio
小灰灰搞电子2 小时前
C++ 文件操作详解
开发语言·c++·文件操作
im_AMBER2 小时前
Leetcode 90 最佳观光组合
数据结构·c++·笔记·学习·算法·leetcode
Trouvaille ~2 小时前
【C++篇】智能指针详解(一):从问题到解决方案
开发语言·c++·c++11·类和对象·智能指针·raii
Wang15303 小时前
c++与Java谁的性能更胜一筹
java·c++
Tipriest_3 小时前
C++ 中 std::move 的使用方法与注意事项
c++·move
yuuki2332333 小时前
【C++】vector底层实现全解析
c++·后端·算法