首页 > 代码库 > [洛谷P1580]yyy loves Easter_Egg I

[洛谷P1580]yyy loves Easter_Egg I

题目大意:很多人@一个人,如果那个人忍不住说话了,就轰炸成功,如果那个人没说话或者别的人没有@他或@很多个人,则轰炸失败。(具体见原题)

解题思路:字符串处理,好好用sscanf即可(细节见代码)。

C++ Code:

#include<cstring>#include<algorithm>#include<cstdio>char s[1050],zha[1050],shuohua[1050],At[1050];int q=1;int main(){	fgets(s,1005,stdin);	sscanf(strstr(s,"@"),"@yyy loves %s",zha);	while(1){		fgets(s,1005,stdin);		if(strlen(s)<5)break;//读入结束		++q;		sscanf(s,"yyy loves %s",shuohua);		if(strcmp(zha,shuohua)==0){//油炸成功 			printf("Successful @yyy loves %s attempt\n",zha);			return 0;		}		if(std::count(s,s+strlen(s),‘@‘)!=1){//队形被破坏,油炸失败			printf("Unsuccessful @yyy loves %s attempt\n%d\nyyy loves %s\n",zha,q,shuohua);			return 0;		}else{			sscanf(strstr(s,"@"),"@yyy loves %s",At);			if(strcmp(At,zha)){//队形被破坏,油炸失败				printf("Unsuccessful @yyy loves %s attempt\n%d\nyyy loves %s\n",zha,q,shuohua);				return 0;			}		}	}	//队形没有被打破	printf("Unsuccessful @yyy loves %s attempt\n%d\nGood Queue Shape\n",zha,q);	return 0;}

 

[洛谷P1580]yyy loves Easter_Egg I