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 ...
随机推荐
- shell的特殊符号的表示
shell中存在一些特殊的符号.这些符号可以帮助我们更好的写出shell来 1.特殊字符 符号 使用 输出 , 枚举分隔符 . 当前目 ...
- 别动我的奶酪:CSV文件数据丢零现象及对策
CSV文件在读入EXCEL时,对于前面有零的数据项,比如电话号码,会自作聪明地丢掉那个零. 比如,我有一个北京客户,其号码为01059178888,如果这是通过CSV文件来的数据,在EXCEL中打开时 ...
- Swift中使用typealias定义一个闭包closure
在OC中我们定义一个Blocks是这样定义的: typedef void (^ZWProgressHUDCompletionBlock)(); 在Swift中定义一个闭包是这种: typealias ...
- Java中ArrayList和LinkedList差别
一般大家都知道ArrayList和LinkedList的大致差别: 1.ArrayList是实现了基于动态数组的数据结构,LinkedList基于链表的数据结构. 2.对于随机訪问get和set.A ...
- 积累的VC编程小技巧之框架窗口及其他
1.修改主窗口风格 AppWizard生成的应用程序框架的主窗口具有缺省的窗口风格,比如在窗口标题条中自动添加文档名.窗口是叠加型的.可改变窗口大小等.要修改窗口的缺省风格,需要重载CWnd::Pre ...
- android中Logcat的深层理解
Android的开发也能够归类为嵌入式设备的开发.即便不是嵌入式开发,依旧要注意对内存和处理的使用.养成一个好的习惯对自己的帮助是非常大的. 在Log的源代码中能够看到这种凝视: The order ...
- UVA11324-- The Largest Clique(SCC+DP)
题目链接 题意:给出一张有向图,求一个结点数最大的结点集,使得该结点集中随意两个结点u和v满足:要么u能够到到v,要么v能够到达u(u和v能够互相到达) 思路:我们能够缩点,用Tarjan求出全部强连 ...
- Android学习-----如何使用sqlite对于后台数据交换,sqlite使用例程入门
SQLite 这是一个非常流行的嵌入式数据库.它支持 SQL 查询,和只使用很少的内存.Android 在集成实施 SQLite,所以每 Android 应用程序能够使用 SQLite 数据库. ...
- Swift - 标签条(UITabBar)标签页控制器(UITabBarController)用法
App底部的tab标签页可以方便的把功能模块划分清楚,只需点击相应的标签页就可以展示完全独立的视图页面,同时各标签页间的视图也可以进行数据交换. TabBarItem系统自带图标样式(System ...
- ACE的构建(VC++6.0环境)
ACE的构建(VC++6.0环境)Windows下ACE的构建1. 将ACE-5.5.zip解压到所需的安装目录,此处以E:/为例,解压后形成ACE_wrappers文件夹,因此ACE将会存在于ACE ...