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;
}
相关推荐
Charles Ray33 分钟前
C++学习笔记 —— 内存分配 new
c++·笔记·学习
重生之我在20年代敲代码34 分钟前
strncpy函数的使用和模拟实现
c语言·开发语言·c++·经验分享·笔记
迷迭所归处6 小时前
C++ —— 关于vector
开发语言·c++·算法
CV工程师小林7 小时前
【算法】BFS 系列之边权为 1 的最短路问题
数据结构·c++·算法·leetcode·宽度优先
white__ice8 小时前
2024.9.19
c++
天玑y8 小时前
算法设计与分析(背包问题
c++·经验分享·笔记·学习·算法·leetcode·蓝桥杯
姜太公钓鲸2338 小时前
c++ static(详解)
开发语言·c++
菜菜想进步8 小时前
内存管理(C++版)
c语言·开发语言·c++
Joker100858 小时前
C++初阶学习——探索STL奥秘——模拟实现list类
c++
科研小白_d.s8 小时前
vscode配置c/c++环境
c语言·c++·vscode