题目大意:输入一串递增的单词序列,需要找出符合条件的单词递增输出,条件是:将一个单词拆成左右两个单词后,能在输入中找到这两个单词。例如单词 alien,可以拆成 a 和 lien,而输入中刚好同时有a和lien,则符合条件,输出alien。又如单词born,无论拆成b和orn,还是bo和rn,亦或是bor和n,都无法在输入中同时找到两个被拆分的单词。

解题思路:把每一个单词拆成两个,然后就看这两个单词是否在输入单词里面。因此可以采用set集合来判断某个单词是否存在输入单词序列里面,用substr分割一个字符串。

/*
ZOJ 1825
Emerald
Tue 12 May 2015
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <string>
#include <set> using namespace std; int main() {
set <string> dict; // a set contains the inputting wotd
string word;
while( cin >> word ) {
dict.insert( word );
} set <string> :: iterator it;
for( it = dict.begin(); it != dict.end(); it ++ ) {
for( int i=1; i < it->length(); i++ ) { // it->substr( pos, len ) : split a string from the pos of the origin
// string, and the splitted string's length is len
if( dict.count( it->substr( 0, i ) ) && dict.count( it->substr( i, it->length() - i ) ) ) {
printf( "%s\n", it->c_str() ); // print the compound word
break; // break, or else this string may be printed again
}
}
} return 0;
}

最新文章

  1. Python UDP broadcast PermissionError: [Errno 13] Permission denied
  2. Win7 Update 遭遇8024200D
  3. Android 长按Listview显示CheckBox,实现批量删除。
  4. 什么是co-training
  5. Understanding Service Types
  6. Android APK方式换肤实现原理
  7. unity 4.x 从入门到精通(持续更新)
  8. Linux软件
  9. 【转】UITextView 修改键盘 的return按钮
  10. Linux修改时间时区并在Tomcat中生效
  11. Web页面布局方式小结
  12. Codeforces 486B - OR in Matrix
  13. 2016年最全面的VR资源盘点,不只有VR视频播放器还有具体到步骤的VR资源
  14. js跨域解决方案
  15. R︱并行计算以及提高运算效率的方式(parallel包、clusterExport函数、SupR包简介)
  16. Install and Configure Apache Kafka on Ubuntu 16.04
  17. 二维码神器QRCoder
  18. MySQL系列详解八:MySQL多线程复制演示-技术流ken
  19. sklearn聚类模型:基于密度的DBSCAN;基于混合高斯模型的GMM
  20. irc

热门文章

  1. oralce11g 注冊表卸载20140810
  2. CSS换行2
  3. zoj 2966 Build The Electric System
  4. window.parent与window.opener的区别与使用
  5. c++ 深浅拷贝
  6. poj 1041 John&#39;s trip 欧拉回路
  7. HDOJ 1226 超级密码(bfs)
  8. Desert King(最优比率生成树)
  9. java解析xml的几种方式
  10. Objective-c Category(类别)