POJ 2803 문자열 인식

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
against
post
after
pre
before
re
again
un
not
Valid suffixes and their meanings are:
er
one who s
ing
to actively
ize
change into
s
multiple instances of
tion
the process of 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
South Central USA 2005
디테일한 처리에 매우 주의해야 한다. 본인은 구체적인 디테일을 잘 처리하지 못해서 여러 번 틀렸는데 어디에서 틀렸는지 모른다.
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;
    //	freopen("in.txt","r",stdin);
    //	freopen("out.txt","w",stdout);
    	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;
    }
  • 좋은 웹페이지 즐겨찾기