POJ 1750 Dictionary(模拟)
来源:互联网 发布:阿里云ftp默认端口号 编辑:程序博客网 时间:2024/05/18 03:02
题目链接:http://poj.org/problem?id=1750
Description
Authors of the new, all-in-one encyclopedia have organized the titles in the order they consider most appropriate for their readers. It's not always alphabetical, because they want to observe some peculiar relationships between them. However, they still want to allow users to look up titles quickly.
They achieve this by adding a carefully calculated number of spaces before every title in the list of titles. They call this structure a dictionary.
A dictionary is represented by a list of words with some number of spaces before certain words. Dictionary format can be described as a set of constraints on sequences of consecutive words starting with the same letter. Any maximal sequence of consecutive words starting with the same letter should satisfy the following rules:
The authors don't feel like giving you a more detailed explanation of what a dictionary is, so they have included an example (see sample input and output) that clarifies their definition.
Your task is to write a program that will convert a given list of words into a dictionary by adding some number of spaces before certain words and preserving the original order of the words.
They achieve this by adding a carefully calculated number of spaces before every title in the list of titles. They call this structure a dictionary.
A dictionary is represented by a list of words with some number of spaces before certain words. Dictionary format can be described as a set of constraints on sequences of consecutive words starting with the same letter. Any maximal sequence of consecutive words starting with the same letter should satisfy the following rules:
- The first word in the group has no spaces before it. Every subsequent word in the group has at least one leading space.
- If
- the first word of the group is deleted and
- one space is deleted before every remaining word and
- the first letter is deleted from every remaining word
then resulting sequence is a dictionary. - the first word of the group is deleted and
The authors don't feel like giving you a more detailed explanation of what a dictionary is, so they have included an example (see sample input and output) that clarifies their definition.
Your task is to write a program that will convert a given list of words into a dictionary by adding some number of spaces before certain words and preserving the original order of the words.
Input
The input consists of at least one and most 100000 words. Each word consists of at least one and at most 10 lower-case letters. There will be no leading or trailing spaces. There will be no blank lines between the words, but there may be an arbitrary number of blank lines at the end of the file.
Output
Write to the output the original words in the same order without any trailing spaces but with the appropriate number of leading spaces, so that this word list is a dictionary. There should be no blank lines between the words, but there may be an arbitrary number of blank lines at the end of the file.
Sample Input
aantantiqueamazebargainbridgebridebribebornbuckettarttantramtrolleyttrytrialzeddoubledormdodormantdonateagainagonyboostbackborn
Sample Output
a ant antique amazebargain bridge bride bribe born buckettart tan tram trolley t try trialzeddouble dorm do dormant donateagain agonyboost back born
Source
Northeastern Europe 1999
题意:
比较每个字符串与前面的字符串相同的字符的个数,如果相同的字符的个数比上一字符串与上上一个字符串相同的字符多,那么就让此字符串前面,在上一字符串已有的空格的基础上多增加一个空格,相反如果是小于,那么就按照当前相同的字符打印空格,PS:说得不明不白的,具体见代码就懂了!
代码如下:
#include <cstdio>#include <cstring>int main(){ char s1[17], s2[17]; int tt=0; while(gets(s2)) { int i=0,j=0; int len1 = strlen(s1); int len2 = strlen(s2); while(i<len1 && j<len2) { if(s1[i] == s2[j]) { i++; j++; } else break; } if(i <= tt) tt = i; if(i > tt) tt += 1; strcpy(s1,s2); for(int i = 0; i < tt; i++) printf(" "); printf("%s\n",s2); } return 0;}
3 0
- POJ 1750 Dictionary(模拟)
- POJ 1750 Dictionary(水~)
- poj 1750 Dictionary(水题:字符串)
- POJ 1750 Dictionary (字符串处理)
- POJ 1750 Dictionary
- noip模拟赛(10.4) 字典序(dictionary)
- 【UVA】12504 - Updating a Dictionary(map,string,vector模拟)
- UVA Andy's First Dictionary(模拟+字符串排序)
- poj 4025 Dictionary Size
- poj 3325(模拟)
- POJ 1008(模拟)
- poj 2632 (模拟)
- POJ 1068(模拟)
- POJ 3087(模拟)
- poj 3087 (模拟)
- POJ 1008 (模拟)
- H-Updating a Dictionary (模拟)
- POJ 2190(模拟策略)
- Android 获取下载文件的真实名字
- ubuntu14.04 安装 lnmp 和配置虚拟机
- Linked List Cycle
- 此时此刻,我已经醒了!
- 区分二维数组与指针数组的区别
- POJ 1750 Dictionary(模拟)
- html float居中
- Android运行时异常“Binary XML file line # : Error inflating class”
- Oracle客户端、Oracle版本不同时登陆表现
- ZOJ1655
- TSPLIB简介与简易解析器实现
- 数据的存储与输入输出(数据类型,常量,变量)
- 人民币转换
- Ipopt 的一个小实例的编译