http://acm.hunnu.edu.cn/online/?action=problem&type=show&id=11354&courseid=0

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 SAIDWHAT 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 quinenot a quinenot a quinenot a quinenot 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 (\) 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"

题意:给出一个字符串,符合"A"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\n");
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)\n",s1);
else
printf("not a quine\n");
} return 0;
}

HUNNU11354:Is the Name of This Problem的更多相关文章

  1. 1199 Problem B: 大小关系

    求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...

  2. No-args constructor for class X does not exist. Register an InstanceCreator with Gson for this type to fix this problem.

    Gson解析JSON字符串时出现了下面的错误: No-args constructor for class X does not exist. Register an InstanceCreator ...

  3. C - NP-Hard Problem(二分图判定-染色法)

    C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144 ...

  4. Time Consume Problem

    I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...

  5. Programming Contest Problem Types

        Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...

  6. hdu1032 Train Problem II (卡特兰数)

    题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能.    (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...

  7. BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】

    2301: [HAOI2011]Problem b Time Limit: 50 Sec  Memory Limit: 256 MBSubmit: 4032  Solved: 1817[Submit] ...

  8. [LeetCode] Water and Jug Problem 水罐问题

    You are given two jugs with capacities x and y litres. There is an infinite amount of water supply a ...

  9. [LeetCode] The Skyline Problem 天际线问题

    A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...

随机推荐

  1. boost.asio包装类st_asio_wrapper开发教程(2014.5.23更新)(一)-----转

    一:什么是st_asio_wrapper它是一个c/s网络编程框架,基于对boost.asio的包装(最低在boost-1.49.0上调试过),目的是快速的构建一个c/s系统: 二:st_asio_w ...

  2. python处理中文字符

    1.在py文件中使用中文字符 unicode.py文件内容如下所示: # -*- coding:utf-8 -*- str_ch = '我们women' uni_ch = u'我们women' pri ...

  3. java 控制表项删除、编辑、添加(实现接口)

    package com.platformda.optimize; import java.awt.BorderLayout; import java.awt.Point; import java.aw ...

  4. ListCtrl控件着色

    最近在写一款山寨的反病毒软件,大致功能已经实现,还有一些细小的环节需要细化. 其中,在界面编程中,就用到了给ListCtrl控件着色,查看了网上一些文章,终于实现了. 其实说白了,原理很简单,就是Li ...

  5. 向大家推荐个android的游戏引擎——cocos2d-x

    最近发现单单用android自带的功能函数来编写游戏,往往有很大的局限性,即耗时长,调试繁琐,没有一定的框架.所以博主发现了游戏引擎这个好东西,游戏引擎所拥有的架构和功能函数,使得游戏的编写更加得心应 ...

  6. RobotFrameWork(十一)AutoItLibrary测试库在win7(64bit)下安装及简单使用

    最近安装AutoItLibrary,发现在win7 x64下无法安装成功,后来经过定位,发现是3rdPartyTools\AutoIt目录下面AutoItX3.dll的问题.因为AutoItX3.dl ...

  7. QT 多线程程序设计(也有不少例子)

    QT通过三种形式提供了对线程的支持.它们分别是,一.平台无关的线程类,二.线程安全的事件投递,三.跨线程的信号-槽连接.这使得开发轻巧的多线程Qt程序更为容易,并能充分利用多处理器机器的优势.多线程编 ...

  8. haproxy 看到的是https,后台是http的原因

    https://www.zjtest6.com/admin/api/menu haproxy 日志: Jun 24 13:23:02 localhost haproxy[23205]: 192.168 ...

  9. setenv 和 set

    setenv 和 set 是在csh系列的命令,当然bash中也有set,还是有出入的.   set 是对当前进程有效,不会传递给子进程 setenv 不仅对当前进程有效,也会传递给子进程.   语法 ...

  10. 学习android内核 -- 内存管理相关

    Android内存管理: 1.当应用程序关闭以后,后台对应的进程并没有真正的退出(处于休眠状态,一般不占用系统CPU的资源),这是为了下次再启动的时候能快速启动. 2.当系统内存不够时,AmS会主动根 ...