Warm up 14 [D] Is the Name of This Problem
| Is the Name of This Problem |
| Time Limit: 3000ms, Special Time Limit:7500ms, Memory Limit:65536KB |
| Total submit users: 41, Accepted users: 33 |
| Problem 12761 : 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:
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, 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 |
| Judge Tips |
|
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 ( "This quotation mark \" is inside the string" "\"" "\"SAID SHE\" SAID SHE" |
| Problem Source |
| mcpc 2012 |
| Submit Discuss Judge Status Problems Ranklist |
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <map> 3 #include <queue> 4 #include <vector> 5 #include <string> 6 #include <cmath> 7 #include <cstdio> 8 #include <cstring> 9 #include <iostream> 10 #include <algorithm> 11 using namespace std; 12 #define maxn 100005 13 #define ll long long 14 #define INF 0x7fffffff 15 char str[maxn]; 16 char s1[maxn]; 17 char s2[maxn]; 18 int n, m; 19 int a[maxn]; 20 int main(){ 21 int cas = 1; 22 while (gets(str)){ 23 if (strcmp(str, "END") == 0)break; 24 memset(s1, 0, sizeof s1); 25 memset(s2, 0, sizeof s2); 26 int n = strlen(str); 27 int k = 0; 28 for (int i = 0; i < n; i++) 29 if (str[i] == '"')a[k++] = i; 30 if (k>2||str[0] != '"' || (k & 1) || str[a[k / 2] + 1] != 32){ printf("not a quine\n"); continue; } 31 int t = 0; 32 for (int i = 1; i < a[k / 2]; i++)s1[t++] = str[i]; 33 t = 0; 34 for (int i = a[k / 2] + 2; i < n; i++)s2[t++] = str[i]; 35 if (strcmp(s1, s2) == 0){ 36 printf("Quine("); printf("%s", s2); printf(")\n"); 37 } 38 else printf("not a quine\n"); 39 } 40 return 0; 41 }
浙公网安备 33010602011771号