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;
}
相关推荐
mit6.8243 分钟前
[vroom] docs | 输入与问题定义 | 任务与运输工具 | json
c++·自动驾驶
charlie11451419121 分钟前
如何使用Qt创建一个浮在MainWindow上的滑动小Panel
开发语言·c++·qt·界面设计
cpp_learners3 小时前
QML与C++交互之创建自定义对象
c++·qt·qml
尘世闲鱼3 小时前
解数独(C++版本)
开发语言·c++·算法·解数独
kyle~4 小时前
C/C++字面量
java·c语言·c++
Mr.Winter`4 小时前
轨迹优化 | 基于激光雷达的欧氏距离场ESDF地图构建(附ROS C++仿真)
c++·人工智能·机器人·自动驾驶·ros·ros2·具身智能
csdn_aspnet4 小时前
C++ n条水平平行线与m条垂直平行线相交的平行四边形的数量
c++
闻缺陷则喜何志丹5 小时前
【BFS】 P10864 [HBCPC2024] Genshin Impact Startup Forbidden II|普及+
c++·算法·宽度优先·洛谷
qianbo_insist6 小时前
c++ python 共享内存
开发语言·c++·python