HUNNU11354:Is the Name of This Problem
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:
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 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 ( "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的更多相关文章
- 1199 Problem B: 大小关系
求有限集传递闭包的 Floyd Warshall 算法(矩阵实现) 其实就三重循环.zzuoj 1199 题 链接 http://acm.zzu.edu.cn:8000/problem.php?id= ...
- 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 ...
- C - NP-Hard Problem(二分图判定-染色法)
C - NP-Hard Problem Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:262144 ...
- Time Consume Problem
I joined the NodeJS online Course three weeks ago, but now I'm late about 2 weeks. I pay the codesch ...
- Programming Contest Problem Types
Programming Contest Problem Types Hal Burch conducted an analysis over spring break of 1999 and ...
- hdu1032 Train Problem II (卡特兰数)
题意: 给你一个数n,表示有n辆火车,编号从1到n,入站,问你有多少种出站的可能. (题于文末) 知识点: ps:百度百科的卡特兰数讲的不错,注意看其参考的博客. 卡特兰数(Catalan):前 ...
- BZOJ2301: [HAOI2011]Problem b[莫比乌斯反演 容斥原理]【学习笔记】
2301: [HAOI2011]Problem b Time Limit: 50 Sec Memory Limit: 256 MBSubmit: 4032 Solved: 1817[Submit] ...
- [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 ...
- [LeetCode] The Skyline Problem 天际线问题
A city's skyline is the outer contour of the silhouette formed by all the buildings in that city whe ...
随机推荐
- Android菜鸟的成长笔记(11)——Android中的事件处理
原文:[置顶] Android菜鸟的成长笔记(11)——Android中的事件处理 Android提供了两种方式来处理事件,一个是基于回调的事件处理,另一个是基于监听的事件处理,举个例子: 基于回调的 ...
- 网络数据(socket)传输总结
环境限定:TCP/IP下的socket网络传输:C/C++开发语言,32/64位机. 目前有两种方式对数据进行传输:1)字符流形式,即将数据用字符串表示:2)结构型方式,即将数据按类型直接传输. 1) ...
- [Java][Android][Process] ProcessBuilder与Runtime差别
在Android中想要进行Ping,在不Root机器的情况下似乎还仅仅能进行底层命调用才干实现. 由于在Java中要进行ICMP包发送须要Root权限. 于是仅仅能通过创建进程来攻克了.创建进程在Ja ...
- linux cent os putty 问题彻底解决办法
出现乱码的根本原因: linux系统和putty使用的编码格式不一致. 解决办法: 1.首先使用命令查看linux当前使用的是什么编码格式 echo $LANG 返回的结果有如下几种情况:1)zh_C ...
- Mybatis自己主动生成代码
在mybatis自己主动生成代码有两种方式: 方式一:是通过使用eclipse作为开发工具.採用maven来构建项目生成的.以下的演示是通过第一种方式. 今天来记录下mybatis-generator ...
- fck编辑器的使用
FCK编辑器的使用 注意:编辑器有浏览器缓存,所以修改配置后,一定要删一下缓存 这个编辑器是采用 html+javascript 开发出来的 通常作为插件来使用: 1,下载插件包 2,解压,加压之后看 ...
- 用Python对体积较大的CSV文件进行比较的经验
用Python对体积较大的CSV文件进行比较的经验 » 进化的测试 | 进化的测试 用Python对体积较大的CSV文件进行比较的经验 python Add comments 八 032010 ...
- IOS中的ViewController 的loadView、viewDidLoad、viewDidUnload
由init.loadView.viewDidLoad.viewDidUnload.dealloc的关系说起: 1 init方法 在init方法中实例化必要的对象(遵从LazyLoad思想) init方 ...
- android app 架构设计02
二:在开放的过程中,尽量把工具类,BaseActivity 放在指定的位置. DateFormat Bitmap Notification Shared Preference Environment ...
- 应用层open(read、write、close)怎样调用驱动open(read、write、close)函数的?
应用层open(read.write.close)怎样调用驱动open(read.write.close)函数的? 华清远见2014-09-29 北京海淀区 张俊浩 三大数据结构关系图