Description
?(>_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.
题目的意思大致就是:
这个题目的其他字符都没有多大的意思,只要看' _ ' 和 ' ! '就好了。
1.当出现一个下划线' _ '时,表示把该字符串再输出一次。
2.当出现一个叹号时,表示打印一个" Hello, world! " 这个字符串。
注意这里的hello world 这里有个空格,所以读入时不能用scanf("%s",a);
所以要用gets(a); 来读入;
当新输出的字符串与旧的字符串完全相同的时候,那么就输出"Yes ";
else 输出 No
这道题主要是考察怎样把一个字符串复制到另一个中去。
#include<stdio.h>
#include<string.h>
int main(){
int T,i,j,len;
char str[300],a[]="Hello, world!";
scanf("%d",&T);
getchar();
while(T--){
//注意这里要用gets,要不然的话遇到空格不会继续读入;
gets(str);
len=strlen(str);
int num1=0,num2=0;
for(i=0;i<len;i++){
if(str[i]=='!') num1++;
else if(str[i]=='_') num2++;
}
//首先判断'_'字符的个数,如果大于1的话,那么肯定是不存在的;
if(num2>1) {puts("No"); continue;}
//如果'_'字符的个数只有一个,但是'!'的个数没有的话,那么也是存在的
if(num2==1 && !num1) {puts("Yes"); continue;}
char ss[10000];
int k=0;
while(num1--){
//这里的13代表的是hello world中字符的个数;
//这里的目的就是把hello world这个字符串复制过去,直接复制的话好像会有问题;
for(i=0;i<13;i++)
ss[k++]=a[i];
}
ss[k]='\0';
printf("%s\n",strcmp(ss,str)==0?"Yes":"No");
}
}
注意这里的hello world 这个字符串的复制。
其实不用函数strcat,直接数出来该字符串的字符的个数,然后再复制到另一个中去。