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;
}
相关推荐
WBluuue28 分钟前
Codeforces 1094 Div1+2(ABCDE)
c++·算法
Languorous.1 小时前
C++智能指针详解:原理、使用及避坑指南
开发语言·c++
lingzhilab1 小时前
零知派ESP32-DFPlayer MP3智能音乐播放器2
c++·mfc
fan_music2 小时前
C语言如何实现C++的类
开发语言·c++
_君莫笑2 小时前
Qt+Qml前后端分离上位机软件技术方案
c++·qt·用户界面·qml
叼烟扛炮2 小时前
C++ 知识点22 函数模板
开发语言·c++·算法·函数模版
￰meteor2 小时前
【移动语义与移动构造】
c++
li星野3 小时前
二分查找六题通关:从标准模板到旋转数组(Python + C++)
java·c++·python
宵时待雨3 小时前
优选算法专题6:模拟
数据结构·c++·算法·leetcode·职场和发展
H Journey3 小时前
C++性能优化
c++·性能优化