HUNNU 11354:Is the Name of This Proble m
http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11354&courseid=0 Problem description
The philosopher Willard Van Quine(1908–2000)described a novel method of conststststststststststing a sentntinininininder to illuststororortitititistststststststststststststststststststststststststststststststinininininststststststststthththththcacacan can can can can arararararararararararararararararararararararararararararaaaaaaaaaaaararararararararararararararararararararararararararprocess as to Quine a phrase.)We can define the Quine operation like so:Quine(A)=「A」A In other wods,if A is a phrase,then Quine(A)is A enclosed in quot tes(「)、フォローアップby space」フォロワーby A.For example:Quine(HELLO WORLD)=「HELLO WORLD」HELLO WORLD Below are some other examples of sentence that can be created by the Quine operation.Note that Quining alws lows senterace。「IS A SENTENCE FRAGMENT」ISA SENTENCE FRAGMENT」ISA SENTENCE FRAGMENTT「ISTHTHTHTHIS THIS PROBLEM」ISTHTHIS PROBLEM「YIELDS FALSEHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOENQUNED」YIELDS FALSEEEEHOHOHOHOHOHOHOEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDENNNNNNNNNNNNNNNNNNNNNNNNNNN..。
Input
The input will consist of a sequence of sentence、one sentence per line、ending with a line that has the single word、END.Each sentence will contan nly up percase letters、spaces、and quot tation marks.Eactenterbence Winterence 1or consecutive spaces.You must decide whether each sentence is the result of a Quine operation.To be a Quine,a sentence must match the following pattern exactly:A quot;mark Any nonempty sequence of letters and spaces(call this phrase A) A quot;mark Aスペース Prase A—exactly as it appared in(2) If it matches this pattern,the sentence is a Quine of the phrase A.Note that phrase A must contain the exact same sequence of characters both times it appars.
Output
The e e e e e will be one line of output for each sentnce in the data set.If the sentnce isthe the rereout of a Quine operation、yourout put shoud be of the form、
Sample Input
「HELLO WORLD」HELLO WORLD「IS A SENTENCE FRAGMENT」ISA SENTENCE FRAGMENTNTENNTENENNT“ISTHTHTHTHTHTHTHTHIS PROBLEM”ISTHTHIS PROBLEM“YIELDS FALSEHOHOHOHOHOHOENQUNED”YLDIELDISFALSEHOHOEHOHOHOHOHOHOHOHOHOHOHOHOEEEEEEHOHOHOHOHOHOHOHOHOEEEEEEEEEEEEEEEEEEHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOENENENENENENENNNNNNNNNNNNNNNNNNES""END
Sample Output
Quine(HELLO WORLD)Quine(IS A SENTENCE FRAGMENT)Quine(IS THE NAME OF THIS PROBLEM)Quine(YIELDS FALSEHOOD WHEN QUNED)not a quinenot a quinenot a quinenot a
Judge Tips
A review of quot;tation marks in strigs: As a reminder、the quot tation mark character is a reglar character、and can be referred to in C、C+、and Java using the standar single-notation、like so:''However、to place a'mark mark double-stretec、+stretecyou must place a backslash(
Aの状況に合わせてQuine(A)を出力する文字列を指定します。そうでないとnot a quineを出力します。
考え方:まず左から右へ第一ペアの二重引用符の文字列を探して、右から左へ二重引用符の後の文字列を探してください。処理はよく比較すればいいです。
The philosopher Willard Van Quine(1908–2000)described a novel method of conststststststststststing a sentntinininininder to illuststororortitititistststststststststststststststststststststststststststststststinininininststststststststthththththcacacan can can can can arararararararararararararararararararararararararararararaaaaaaaaaaaararararararararararararararararararararararararararprocess as to Quine a phrase.)We can define the Quine operation like so:Quine(A)=「A」A In other wods,if A is a phrase,then Quine(A)is A enclosed in quot tes(「)、フォローアップby space」フォロワーby A.For example:Quine(HELLO WORLD)=「HELLO WORLD」HELLO WORLD Below are some other examples of sentence that can be created by the Quine operation.Note that Quining alws lows senterace。「IS A SENTENCE FRAGMENT」ISA SENTENCE FRAGMENT」ISA SENTENCE FRAGMENTT「ISTHTHTHTHIS THIS PROBLEM」ISTHTHIS PROBLEM「YIELDS FALSEHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOENQUNED」YIELDS FALSEEEEHOHOHOHOHOHOHOEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEDEDEDEDEDEDEDEDEDEDEDEDEDEDEDENNNNNNNNNNNNNNNNNNNNNNNNNNN..。
Input
The input will consist of a sequence of sentence、one sentence per line、ending with a line that has the single word、END.Each sentence will contan nly up percase letters、spaces、and quot tation marks.Eactenterbence Winterence 1or consecutive spaces.You must decide whether each sentence is the result of a Quine operation.To be a Quine,a sentence must match the following pattern exactly:
Output
The e e e e e will be one line of output for each sentnce in the data set.If the sentnce isthe the rereout of a Quine operation、yourout put shoud be of the form、
Quine(A)
、where A isthe phrase the phrase to Quie the crininininininininininininininininininininininininininine thethethethethe sesesesesesesesesesesesese se se se se se se se se thethethethethethethethethethethethethethethethethethethethethethethethethethethe sesesesese se se se e.Sample Input
「HELLO WORLD」HELLO WORLD「IS A SENTENCE FRAGMENT」ISA SENTENCE FRAGMENTNTENNTENENNT“ISTHTHTHTHTHTHTHTHIS PROBLEM”ISTHTHIS PROBLEM“YIELDS FALSEHOHOHOHOHOHOENQUNED”YLDIELDISFALSEHOHOEHOHOHOHOHOHOHOHOHOHOHOHOEEEEEEHOHOHOHOHOHOHOHOHOEEEEEEEEEEEEEEEEEEHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOHOENENENENENENENNNNNNNNNNNNNNNNNNES""END
Sample Output
Quine(HELLO WORLD)Quine(IS A SENTENCE FRAGMENT)Quine(IS THE NAME OF THIS PROBLEM)Quine(YIELDS FALSEHOOD WHEN QUNED)not a quinenot a quinenot a quinenot a
Judge Tips
A review of quot;tation marks in strigs: As a reminder、the quot tation mark character is a reglar character、and can be referred to in C、C+、and Java using the standar single-notation、like so:''However、to place a'mark mark double-stretec、+stretecyou must place a backslash(
\
)in front of it.If you dot it will be interpreted as the end of the string,causing sysntax errors.For example:「This quot;tation mark」is inde the string「\SAE」Aの状況に合わせてQuine(A)を出力する文字列を指定します。そうでないとnot a quineを出力します。
考え方:まず左から右へ第一ペアの二重引用符の文字列を探して、右から左へ二重引用符の後の文字列を探してください。処理はよく比較すればいいです。
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
char s1[10005],s2[10005];
char str[20005];
int main()
{
int len,i,l1,l2;
while(gets(str))
{
if(!strcmp(str,"END"))
break;
len = strlen(str);
l1 = l2 = 0;
if(str[0] != '"')// “
{
printf("not a quine
");
continue;
}
for(i = 1; i<len; i++)//
{
if(str[i]!=34)
s1[l1++] = str[i];
else
{
s1[l1] = '"';
break;
}
}
for(i = len-1; i>=0; i--)//
{
if(str[i] == ' ' && str[i-1] == '"')
{
s2[l2] = '\0';
break;
}
else
s2[l2++] = str[i];
}
char tem;
for(i = 0; i<l2/2; i++)//
{
tem = s2[l2-1-i];
s2[l2-1-i] = s2[i];
s2[i] = tem;
}
if(!strcmp(s1,s2))
printf("Quine(%s)
",s1);
else
printf("not a quine
");
}
return 0;
}