?(>_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. |
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
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.
这道坑题,题意看了好久,唉,不想多说,其实只要看下划线和感叹号即可
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#include <stack>
using namespace std;
char s[1000];
int main()
{
int n;
int xia,gan;
cin >> n;
getchar();
while(n--)
{
gets(s);
int len = strlen(s);
xia = gan = 0;
for(int i = 0; i<len; i++)
{
if(s[i] == '_')
xia++;
else if(s[i] == '!')
gan++;
}
if(xia>1)
printf("No\n");
else if(xia == 1 && !gan)
printf("Yes\n");
else if(xia && gan)
printf("No\n");
else
{
int l;
char str[20];
if(len%13)
{
printf("No\n");
}
else if(len == 13)
{
if(!strcmp(s,"Hello, world!"))
printf("Yes\n");
else
printf("No\n");
}
else
{
int flag = 1;
for(int i = 13; i<=len-13; i+=13)
{
if(s[i] == 'H' && s[i+1] == 'e' && s[i+2] == 'l' && s[i+3] == 'l' && s[i+4] == 'o' && s[i+5] == ',' && s[i+6] == ' ' && s[i+7] == 'w' && s[i+8] == 'o' && s[i+9] == 'r' && s[i+10] == 'l' && s[i+11] == 'd' && s[i+12] == '!')
flag == 1;
else
{
flag = 0;
break;
}
}
if(flag)
printf("Yes\n");
else
printf("No\n");
}
}
}
return 0;
}