ZOJ 3775 ?(>_o)!
2014-04-07 21:13
253 查看
链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5238
题目:
?(>_o)!
Time Limit: 2 Seconds Memory Limit: 65536 KB
?(>_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.
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].
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版本:
非stl版本:
题目:
?(>_o)!
Time Limit: 2 Seconds Memory Limit: 65536 KB
?(>_o)! is a pseudo-object-oriented programming language. It implements the following commands:
Command | Description |
---|---|
? | Check whether the character '?' is in the program's source code. If '?' does not exist in the program's source, the hardware will catch fire or explode. |
( | It tries to match ')', although mismatch of brackets does not matter at all. |
> | Increase the internal accumulator. |
_ | Print the program's source code. |
o | Instantiate an object of a new sub class of the generic super class. Due to the best principles of object hiding, this object cannot be accessed in any way. |
) | Just matches '('. It's for patient with obsessive-compulsive disorder. However, mismatch of brackets does not matter at all. |
! | Print "Hello, world!". |
Other characters | Be treated as comments rather than instruction. |
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
4 Hello, world! source_code source__code ?(>_o)!
Sample Output
Yes Yes No No
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; }
相关文章推荐
- Origami
- 《Box2D for Flash Games》翻译 在世界里添加刚体(A)
- 学习心得-1
- 产品原型设计工具 Balsamiq Mockups(转)
- ReportStudio入门教程(十三) - 列表的复杂表头之隐藏
- spring4+hibernate4 configlocation出错
- 最近关注的几个算法
- 详细解析Java中抽象类和接口的区别
- 第三题 数组中最小的K个数
- 最大匹配-HDOJ 2458 Kindergarten
- Hibernate get和load区别
- VMware中Linux系统网络配置(转载)
- Head First SQL:学习笔记1/2
- fatal error LNK1123: failure during conversion to COFF
- mysql use
- jquery checkbox 全选失效问题
- VSPM虚拟串口使用
- linux中mv命令使用详解(移动文件或者将文件改名)
- IOS计算MD5值
- [ACM] poj 1496 Word Index(组合计数)