1. 程式人生 > >[洛谷P1580]yyy loves Easter_Egg I

[洛谷P1580]yyy loves Easter_Egg I

include 失敗 nbsp highlight code tro sscanf div ets

題目大意:[email protected],如果那個人忍不住說話了,就轟炸成功,[email protected]@很多個人,則轟炸失敗。(具體見原題)

解題思路:字符串處理,好好用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),[email protected]
/* */)!=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