Defining Moment
Time Limit: 1000MS |
|
Memory Limit: 65536K |
Total Submissions: 1341 |
|
Accepted: 603 |
Description
As a homework assignment, you have been tasked with creating a program that provides the meanings for many different words. As you dislike the idea of writing a program that just prints definitions of words, you decide to write a program that can print definitions of many variations of just a handful of different root words. You do this by recognizing common prefixes and suffixes. Since your program is smart enough to recognize up to one prefix and one suffix per word, it can process many forms of each word, significantly reducing the number of rote definitions required.
For this problem, you'll be writing the prefix/suffix processing portion of the program.
Valid prefixes and their meanings are:
anti<word> |
against <word> |
post<word> |
after <word> |
pre<word> |
before <word> |
re<word> |
<word> again |
un<word> |
not <word> |
Valid suffixes and their meanings are:
<word>er |
one who <word>s |
<word>ing |
to actively <word> |
<word>ize |
change into <word> |
<word>s |
multiple instances of <word> |
<word>tion |
the process of <word>ing |
Note that suffixes are tied more tightly to their root word and should therefore be expanded last. For example, the word ``vaporize" would be expanded through the following steps:
unvaporize
not vaporize
not change into vapor
Of course, the definitions are not exactly right, but how much polish does the professor expect for a single homework grade?
Input
Input to this problem will begin with a line containing a single integer n indicating the number of words to define. Each of the following n lines will contain a single word. You need to expand at most one prefix and one suffix, and each word is guaranteed to have a non-empty root (i.e., if the prefix and/or suffix are removed, a non-empty string will remain). Each word will be composed of no more than 100 printable characters.
Output
For each word in the input, output the expanded form of the word by replacing the prefix and/or suffix with its meaning.
Sample Input
6
vaporize
prewar
recooking
root
repopularize
uninforming
Sample Output
change into vapor
before war
to actively cook again
root
change into popular again
not to actively inform
Source
要非常注意细节的处理,本人就是由于具体的细节没有处理好,导致错了很多次都不知道在哪儿错了。。
Source Code
Problem: 2803
|
|
User: bingshen
|
Memory: 172K |
|
Time: 0MS |
Language: C++ |
|
Result: Accepted
|
-
Source Code
#include<stdio.h>
#include<string.h>
char word[105];
int main()
{
int n,l,i;
scanf("%d",&n);
while(n--)
{
memset(word,'/0',sizeof(word));
bool flag=false;
bool loop=false;
scanf("%s",word);
l=strlen(word);
if(word[0]=='u'&&word[1]=='n')
{
for(i=0;i<l-2;i++)
word[i]=word[i+2];
word[l-2]='/0';
printf("not ");
}
if(word[0]=='p'&&word[1]=='r'&&word[2]=='e')
{
for(i=0;i<l-3;i++)
word[i]=word[i+3];
word[l-3]='/0';
printf("before ");
}
if(word[0]=='a'&&word[1]=='n'&&word[2]=='t'&&word[3]=='i')
{
for(i=0;i<l-4;i++)
word[i]=word[i+4];
word[l-4]='/0';
printf("against ");
}
if(word[0]=='p'&&word[1]=='o'&&word[2]=='s'&&word[3]=='t')
{
for(i=0;i<l-4;i++)
word[i]=word[i+4];
word[l-4]='/0';
printf("after ");
}
if(word[0]=='r'&&word[1]=='e')
{
for(i=0;i<l-2;i++)
word[i]=word[i+2];
word[l-2]='/0';
flag=true;
}
l=strlen(word);
if(word[l-3]=='i'&&word[l-2]=='n'&&word[l-1]=='g')
{
word[l-3]='/0';
printf("to actively %s",word);
if(!flag)
printf("/n");
loop=true;
}
if(word[l-3]=='i'&&word[l-2]=='z'&&word[l-1]=='e')
{
word[l-3]='/0';
printf("change into %s",word);
if(!flag)
printf("/n");
loop=true;
}
if(word[l-4]=='t'&&word[l-3]=='i'&&word[l-2]=='o'&&word[l-1]=='n')
{
word[l-4]='/0';
printf("the process of %s",word);
printf("ing");
if(!flag)
printf("/n");
loop=true;
}
if(word[l-1]=='s')
{
word[l-1]='/0';
printf("multiple instances of %s",word);
if(!flag)
printf("/n");
loop=true;
}
if(word[l-2]=='e'&&word[l-1]=='r')
{
word[l-2]='/0';
printf("one who %s",word);
printf("s");
if(!flag)
printf("/n");
loop=true;
}
if(flag&&!loop)
printf("%s again/n",word);
if(flag&&loop)
printf(" again/n");
if(!flag&&!loop)
printf("%s/n",word);
}
return 0;
}
分享到:
相关推荐
北大POJ1016-Numbers That Count【字符串处理】 解题报告+AC代码
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
上面可能有poj的题目,hdu的题目,spoj的题目,sgu的题目,hust上的题目,fzu上的题目
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
LeetCode判断字符串是否循环 :bookmark_tabs:Plan 动态规划 背包问题 动态规划 POJ 3267 POJ 1260 POJ 1015 POJ 3176 POJ 1080 POJ 1159 POJ 2533 POJ 1836 Leetcode 70 Leetcode 309 搜索 DFS POJ 2488 POJ 3083 ...
在进行ACM编程训练时做字符串专题的一些题目(POJ1782,POJ1790,POJ1951,POJ2003,POJ2121)
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
poj分类poj分类poj分类poj分类
北大POJ1159-Palindrome 解题报告+AC代码
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
POJ1503解答 POJ1503解答,正确答案(已通过POJ)
POJ1083的代码,POJ1083的代码,POJ1083的代码
POJ1048,加强版的约瑟夫问题 难度中等
poj 百练 题目分类 poj 百练 题目分类
北大POJ2002-Squares 解题报告+AC代码
poj 1001答案