ZOJ 1825 compoud words
题目大意:输入一串递增的单词序列,需要找出符合条件的单词递增输出,条件是:将一个单词拆成左右两个单词后,能在输入中找到这两个单词。例如单词 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;
}
ZOJ 1825 compoud words的更多相关文章
- ZOJ 1825 Compound Words
Compound Words Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original ...
- ZOJ People Counting
第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ 3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...
- 【BZOJ 1061】【Vijos 1825】【NOI 2008】志愿者招募
http://www.lydsy.com/JudgeOnline/problem.php?id=1061 https://vijos.org/p/1825 直接上姜爷论文... #include< ...
- ZOJ 3686 A Simple Tree Problem
A Simple Tree Problem Time Limit: 3 Seconds Memory Limit: 65536 KB Given a rooted tree, each no ...
- ZOJ Problem Set - 1394 Polar Explorer
这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...
- ZOJ Problem Set - 1392 The Hardest Problem Ever
放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...
- ZOJ Problem Set - 1049 I Think I Need a Houseboat
这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...
- ZOJ Problem Set - 1006 Do the Untwist
今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...
- ZOJ Problem Set - 1001 A + B Problem
ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",& ...
随机推荐
- POJ 1679:The Unique MST(次小生成树&&Kruskal)
The Unique MST Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19941 Accepted: 6999 D ...
- GDB调试之core文件(如何定位到Segment fault)
core dump又叫核心转储,当程序运行过程中发生异常,程序异常退出时,由操作系统把程序当前的内存状况存储在一个core文件中,叫core dump.(内部实现是:linux系统中内存越界会收到SI ...
- iOS网络请求基础
这篇是关于网络请求的,结合公司的实际情况编写,如果有不同意见欢迎留言共同讨论. iOS在9.0之后彻底放弃了NSURLConnection,现在已经改用了NSURLSession进行网络请求.一般现在 ...
- PrintWriter与outputStream区别
网上截取: printWriter:我们一般用来传的是对像 而outputStream用来传的是二进制,故上传文件时,一定要使用此. PrintWriter以字符为单位,支持汉字,OutputStre ...
- 在InteliJ IDEA中写Dart及配置IDEA - Dart Plugin
此文运用的是优雅的Markdown而书 Dart官方建议使用的编译器是DartEditor,我下载下来看下,和Eclipse的界面很相像.对于Eclipse,我是既爱又恨,爱它的稳定,恨它的功能没有I ...
- divmod数字处理函数
divmod(a,b)函数 中文说明: divmod(a,b)方法返回的是a//b(除法取整)以及a对b的余数 返回结果类型为tuple 参数: a,b可以为数字(包括复数) 版本: 在python2 ...
- synchronized和vilatile
第一个程序 public class Test06 implements Runnable{ public int a = 0; public static void main(String[] ar ...
- 阿里云ECS每天一件事D3:挂载硬盘
阿里云的系统盘通常都不大,对于我们的日常使用,基本不足,因此都会额外购买至少一块硬盘,作为存储数据之用. 数据盘要经过分区.格式化.挂载三个步骤,方能正常使用. 1.数据盘的分区 先使用fdisk命 ...
- C++头文件的包含顺序研究
一.<Google C++ 编程风格指南>里的观点 公司在推行编码规范,领导提议基本上使用<Google C++ 编程风格指南>.其中<Google C++ 编程风格指南 ...
- C++_template_栈的链式存储及实现
由于在C++数据结构中的代码不完整,特补全.等日后当工程库调用. 若有疑问,请留言. #include<iostream> using namespace std; template< ...