zoukankan      html  css  js  c++  java
  • HUNAN NORMAL UNIVERSITY ACM 11354

    Is the Name of This Problem
    Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:32768KB
    Total submit users: 23, Accepted users: 21
    Problem 11354 : No special judgement
    Problem description
      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 as to Quine a phrase.) We can define the Quine operation like so:
    Quine(A) = "A" A
    

    In 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 pattern exactly:

    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 a quine. 

    Sample Input
    "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 SAID
    WHAT ABOUT "WHAT ABOUT"
    " NO EXTRA SPACES " NO EXTRA SPACES
    "NO"QUOTES" NO"QUOTES
    ""
    END
    Sample Output
    Quine(HELLO WORLD)
    Quine(IS A SENTENCE FRAGMENT)
    Quine(IS THE NAME OF THIS PROBLEM)
    Quine(YIELDS FALSEHOOD WHEN QUINED)
    not a quine
    not a quine
    not a quine
    not a quine
    not a quine

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
    int main()
    {
        char str[1000],a[1000],b[1000];
        int i,len,j,count,flag,t,tag;
        while(gets(str)&&(strcmp(str,"END")!=0))
        {
            if(str[0]!='"')
            {
                printf("not a quine
    ");
                continue;
            }
            len=strlen(str);
            memset(a,'',sizeof(a));
            memset(b,'',sizeof(b));
            count=0;
            for(i=0; i<len; i++)
            {
                if(str[i]=='"')
                    count++;
            }
            if(count>2)
            {
                printf("not a quine
    ");
                continue;
            }
            flag=1;
            tag=0;
            for(i=0; i<=len; i++)
            {
                if(str[i]=='"')
                {
                    flag=!flag;
                    t=0;
                    if(flag!=0)
                    {
                        if(str[i+1]==' ')
                            i+=2;
                        else
                        {
                            tag=0;
                            break;
                        }
                    }
                    else
                        i+=1;
                }
                if(flag==0)
                {
                    a[t++]=str[i];
                    continue;
                }
                if(flag!=0)
                {
                    b[t++]=str[i];
                }
                if(str[i]=='')
                {
                    if(strcmp(a,b)==0)
                        tag=1;
                }
            }
            if(tag)
                printf("Quine(%s)
    ",a);
            else
                printf("not a quine
    ");
        }
        return 0;
    }
  • 相关阅读:
    hadoop2.2.0 centos6.4 编译安装详解
    Hadoop 2.2.0的高可用性集群中遇到的一些问题(64位)
    Visual Studio 常用快捷键
    Android(1)—Mono For Android 环境搭建及破解
    IbatisNet SqlMap.config配置节导致的程序无法通过
    CAD数据分块,偏移校准,加载到百度地图、高德地图、谷歌等地图上
    数据库SQL优化大总结
    Scratch 3下载,最新版Scratch下载,macOS、Windows版
    高性能网站设计之缓存更新的套路
    【验证无效】MySQL的count(*)的优化,获取千万级数据表的总行数
  • 原文地址:https://www.cnblogs.com/lxm940130740/p/3293035.html
Copyright © 2011-2022 走看看