Is the Name of This Problem

来源:互联网 发布:淘宝无线装修入口 编辑:程序博客网 时间:2024/05/21 10:51
The philosopher Willard Van Orman Quine (1908–2000) described a novel method of constructing a sentence in order to illustrate the contradictions that can arise from self-reference. This operation takes as input a single phrase and produces a sentence from that phrase.  (The author Douglas R.Hofstadter refers to this process asto Quine a phrase.) We can de ne the Quine operation like so:                        Quine(A) ="A" AIn other words, if A is a phrase, then Quine (A) is A enclosed in quotes (" "), followed by a space,followed by A. For example:    Quine(HELLO WORLD) = "HELLO WORLD" HELLO WORLD    Below are some other examples of sentences that can be created by the Quine operation. Note that Quining allows sentences to be indirectly self-referential, such as the last sentence below.    "IS A SENTENCE FRAGMENT" IS A SENTENCE FRAGMENT    "IS THE NAME OF THIS PROBLEM" IS THE NAME OF THIS PROBLEM    "YIELDS FALSEHOOD WHEN QUINED" YIELDS FALSEHOOD WHEN QUINED    Your goal for this problem is to take a sentence and decide whether the sentence is the result of a Quine operation.

Input

    The input will consist of a sequence of sentences, one sentence per line, ending with a line that has the single word, `END'. Each sentence will contain only uppercase letters, spaces, and quotation marks.    Each sentence will contain between 1 and 80 characters and will not have any leading, trailing, or 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 patternexactly :    1. A quotation mark    2. Any nonempty sequence of letters and spaces (call this phrase A )    3. A quotation mark    4. A space    5. Phrase    A | exactly as it appeared 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 appears.

Output

There will be one line of output for each sentence in the data set. If the sentence is the result of a Quine operation, your output should be of the form, `Quine(A)', where A is the phrase to Quine to create the sentence.If the sentence is not the result of a Quine operation, your output should be the phrase, ` not aquine'.

Note:

    A review of quotation marks in strings:    As a reminder, the quotation mark character is a regular character, and can be referred to in C,    C++, and Java using the standard single-quote notation, like so:'"'    However, to place a quotation mark inside a double-quoted string in C, C++, and Java, you must place a backslash (n) in front of it. If you do not it will be interpreted as the end of the string, causing syntax errors.     For example:    "This quotation mark \" is inside the string"    "\""    "\"SAID SHE\" SAID SHE"

SampleInput

"HELLO WORLD" HELLO WORLD"IS A SENTENCE FRAGMENT" IS A SENTENCE FRAGMENT"IS THE NAME OF THIS PROBLEM" IS THE NAME OF THIS PROBLEM"YIELDS FALSEHOOD WHEN QUINED" YIELDS FALSEHOOD WHEN QUINED"HELLO" I SAIDWHAT ABOUT "WHAT ABOUT"" NO EXTRA SPACES " NO EXTRA SPACES"NO"QUOTES" NO"QUOTES""END

SampleOutput

Quine(HELLO WORLD)Quine(IS A SENTENCE FRAGMENT)Quine(IS THE NAME OF THIS PROBLEM)Quine(YIELDS FALSEHOOD WHEN QUINED)not a quinenot a quinenot a quinenot a quinenot a quine

一道水题,唯一注意的是要判断 二次引用 /“ ,还有一定得是( ” )开头的 ”A“ A,中间还得有空格(-_-WA了一次才意识到)

#include <cstdio>#include <cstring>using namespace std;char A[100000],B[100000],C[100000];bool Handle(int len){    int Count_B=0,Count_C=0,i;    if(A[1]!='"') return false;    for(i=2;i<=len;i++)    {        if(A[i]=='"')        {            if(A[i-1]!=92)  break;            else            B[++Count_B] = A[i];        }        else if(A[i]==92&&A[i]&&A[i+1]=='"')   continue;        else B[++Count_B] = A[i];    }    if(A[++i]!=' ') return false;    for(i = i+1;i<=len;i++) C[++Count_C]=A[i];    B[Count_B+1]=C[Count_C+1]=0; //puts(B+1);puts(C+1);    if(!Count_B||!Count_C) return false;    return !strcmp(B+1,C+1);}int main(void){    //freopen("E:\\test.txt","r",stdin);    while(gets(A+1)!=NULL)    {        if(!strcmp("END",A+1)) break;        bool flag = Handle(strlen(A+1));        if(flag)   printf("Quine(%s)\n",C+1);        else        printf("not a quine\n");    }
0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 杭州居住告知单怎么办 郑州有房怎么办暂住证 郑州买车怎么办暂住证 在青岛办暂住证怎么办 异地买车暂住证怎么办 广州暂住证过期了怎么办 杭州暂住证过期了怎么办 居住卡到期了怎么办 居住卡过期了怎么办 在合肥办暂住证怎么办 在西安办暂住证怎么办 杭州没办暂住证怎么办 暂住证超过2月怎么办 机动车大本丢了怎么办 北京老年卡2018怎么办 暂住卡过期了怎么办 我暂住证过期了怎么办 我没租房怎么办暂住证 孩子异地入学籍怎么办 孩子入不了学籍怎么办 常州没有暂住证怎么办牌照 东莞居住证过期了怎么办 杭州告知单过期怎么办 杭州暂住证到期了怎么办 在杭州租房怎么办暂住证 杭州暂住证丢了怎么办 在宾馆住怎么办暂住证 上海学车暂住证怎么办 环保车贴丢了怎么办 交通事故交警不处理怎么办 哈尔滨冰雪大世界夏天怎么办 下围棋没天赋怎么办 围棋计算力不好怎么办? 围棋3段后怎么办 遇到围棋中的断怎么办 手机出现等待中怎么办 小孩和同学打架怎么办 听到同学议论我怎么办 写小说对话枯燥怎么办 打架对面人多怎么办 雪纺衬衣透怎么办