ZOJ 3775 ?(>_o)!
来源:互联网 发布:mysql union all 效率 编辑:程序博客网 时间:2024/05/18 18:56
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5238
题目:
?(>_o)! is a pseudo-object-oriented programming language. It implements the following commands:
However, it's only another joke programming language. There is even no way to access the accumulator. But it's one of easiest to finish a "Hello world" program or a quine program. A quine is a computer program which takes no input and produces a copy of its own source code as its only output. Your task is to judge whether a ?(>_o)! program is a quine.
Input
There are multiple test cases. The first line of input is an integer T indicates the number of test cases. For each test case:
There is one line of string represents the source code of a ?(>_o)! program. The program contains no more than 256 characters. The ASCII value of each character is within [32, 126].
Output
For each test case, output "Yes" if it is a quine. Otherwise, output "No".
Sample Input
4Hello, world!source_codesource__code?(>_o)!
Sample Output
YesYesNoNo
Hint
The output of the four sample programs are {"Hello, world!", "source_code", "source__codesource__code", "?(>_o)!Hello, world!"} respectively. Therefore the first two programs are quines, and the last two are not.
Luckily, there is a '?' in the fourth program, so the hardware will not catch fire or explode during running the fourth program.
解题思路:
简单模拟
代码:
stl版本:
#include <iostream>#include <string>using namespace std;string s, ss;int main(){int t;while(cin >> t){cin.ignore();//相当于getchar()while(t--){s = ss = "";getline(cin, s);//读取一行,此处不能用cin,因为cin读到空格就停int len = s.length();for(int i = 0; i < len; i++){if('_' == s[i]){ss += s;}else if('!' == s[i]){ss += "Hello, world!";}}cout << (s == ss ? "Yes" : "No") << endl;}}return 0;}
非stl版本:
#include <iostream>#include <cstring>#include <string>#include <cstdio>using namespace std;const int MAXN = 100000;char s[MAXN], ss[MAXN];int main(){int t;char st[] = "Hello, world!";while(~scanf("%d", &t)){getchar();while(t--){for(int i = 0; i < MAXN; i++){ss[i] = ' ';}gets(s);int len = strlen(s);int ls = 0;for(int i = 0; i < len; i++){if('_' == s[i]){for(int j = 0; j < len; j++){ss[ls++] = s[j];}}else if('!' == s[i]){for(int j = 0; j < strlen(st); j++){ss[ls++] = st[j];}}}ss[ls] = '\0';printf("%s\n", 0 == strcmp(s, ss) ? "Yes" : "No");}}return 0;}
- zoj 3775 ?(>_o)!
- ZOJ 3775 ?(>_o)!(模拟)
- ZOJ 3775 ?(>_o)!
- ZOJ 3775 ?(>_o)!
- ?(>_o)!
- 第14届浙江大学程序设计竞赛 I. ?(>_o)! (ZOJ 3775)
- ZOJ3775:?(>_o)!
- ZOJ3775 ?(>_o)!
- ZOJ3775 ?(>_o)!
- ZOJ3775-?(>_o)!
- 字符串水题 N - ?(>_o)!
- zoj 3775
- ZOJ-3775
- zoj 3775
- Java web 服务_O'REILLY_个人读书笔记
- 算法学习 - 链表之归并排序_O(1)空间_O(NlogN)时间_C++
- ZOJ
- ZOJ
- IOS计算MD5值
- 《算法导论》笔记 第7章 7.2快速排序的性能
- Head First SQL:学习笔记1/2
- OpenCV学习C++接口:图像锐化
- spring4+hibernate4 configlocation出错
- ZOJ 3775 ?(>_o)!
- 《Box2D for Flash Games》翻译 (一)hello box2d world
- stm32驱动段式lcd液晶显示--非使用1621驱动芯片驱动
- admob_广告添加__教程
- 在创业型软件公司的收获
- codeforces 414b(数位DP)
- 清明节左作业
- 详细解析Java中抽象类和接口的区别
- mysql use