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;
}
相关推荐
小李小李快乐不已9 分钟前
栈和堆理论基础
c++·算法·leetcode
夏幻灵10 分钟前
CMD是什么
c++
HABuo23 分钟前
【Linux进程(一)】进程深入剖析-->进程概念&PCB的底层理解
linux·运维·服务器·c语言·c++·后端·进程
图形学爱好者_Wu26 分钟前
每日一个C++知识点|菱形继承
c++·程序员·编程语言
.简.简.单.单.37 分钟前
Design Patterns In Modern C++ 中文版翻译 第十章 外观模式
c++·设计模式·外观模式
十五年专注C++开发1 小时前
Jieba库: 一个中文分词领域的经典库
c++·分布式·自然语言处理·中文分词
_OP_CHEN1 小时前
【C++数据结构进阶】从 Redis 底层到手写实现!跳表(Skiplist)全解析:手把手带你吃透 O (logN) 查找的神级结构!
数据结构·数据库·c++·redis·面试·力扣·跳表
菜菜的院子1 小时前
vcpkg配置
c++
我的offer在哪里2 小时前
c++的回调函数
开发语言·c++
Hello eveybody2 小时前
C++四级考试要点
开发语言·c++