POJ 2803 문자열 인식
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
un
not
Valid suffixes and their meanings are:
one who
to actively
change into
multiple instances of
the process of
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
#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;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
cocos2d Lua 학습(一)ios에서 루아 함수 호출 및 전참 방법 lua 코드: 출력 결과: lua 호출 C++ 방법: add 함수: lua 코드: 출력 결과: 함수를 호출합니다. 함수를 호출하려면 다음 협의를 따르십시오. 우선, 호출할 함...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.