社区讨论

感觉好多坑

P1042[NOIP 2003 普及组] 乒乓球参与者 2已保存回复 1

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
1 条
当前快照
1 份
快照标识符
@mdifkdz0
此快照首次捕获于
2025/07/25 14:18
7 个月前
此快照最后确认于
2025/07/25 14:33
7 个月前
查看原帖
我的第一个代码
CPP
#include<iostream>
using std::string;using std::cin;using std::cout;
char a[10001][101],n;
int f[1000001];
int main(){
	for(;;){
		char a;
		scanf("%c",&a);
		if(a=='E') break;
		if(a=='W') f[++n]=1;
		if(a=='L') f[++n]=2;
	}
	int i=1;
	while(1){
		int A=0,B=0;
		if(f[i]==0) break;
		while(1){
			if(A==11 || B==11) break;
			if(f[i]==0) break;
			if(f[i]==1) A++;
			if(f[i++]==2) B++;
		}
		printf("%d:%d\n",A,B);
	}
	printf("\n");
	i=1;
	while(1){
		int A=0,B=0;
		if(f[i]==0) break;
		while(1){
			if(A==21 || B==21) break;
			if(f[i]==0) break;
			if(f[i]==1) A++;
			if(f[i++]==2) B++;
		}
		printf("%d:%d\n",A,B);
	}
}
CPP
if(A==11 || B==21) break;
要放后面
CPP
#include<iostream>
using std::string;using std::cin;using std::cout;
char a[10001][101],n;
int f[1000001];
int main(){
	for(;;){
		char a;
		scanf("%c",&a);
		if(a=='E') break;
		if(a=='W') f[++n]=1;
		if(a=='L') f[++n]=2;
	}
	int i=1;
	while(1){
		int A=0,B=0;
		while(1){
			if(A==11 || B==11) break;
			if(f[i]==0) break;
			if(f[i]==1) A++;
			if(f[i++]==2) B++;
		}
		printf("%d:%d\n",A,B);
		if(f[i]==0) break;
	}
	printf("\n");
	i=1;
	while(1){
		int A=0,B=0;
		while(1){
			if(A==21 || B==21) break;
			if(f[i]==0) break;
			if(f[i]==1) A++;
			if(f[i++]==2) B++;
		}
		printf("%d:%d\n",A,B);
		if(f[i]==0) break;
	}
}
RE
发现a数组好幽默,删了
WA
又发现A和B至少相差一才结束
CPP
#include<iostream>
using std::string;using std::cin;using std::cout;
int abs(int a){
	if(a<0) return a*-1;
	return a;
}
int n;
int f[1000001];
int main(){
	for(;;){
		char a;
		scanf("%c",&a);
		if(a=='E') break;
		if(a=='W') f[++n]=1;
		if(a=='L') f[++n]=2;
	}
	int i=1;
	while(1){
		int A=0,B=0;
		while(1){
			if((A==11 || B==11) && (abs(A-B)>1)) break;
			if(f[i]==0) break;
			if(f[i]==1) A++;
			if(f[i++]==2) B++;
		}
		printf("%d:%d\n",A,B);
		if(f[i]==0) break;
	}
	printf("\n");
	i=1;
	while(1){
		int A=0,B=0;
		while(1){
			if((A==21 || B==21) && (abs(A-B)>1)) break;
			if(f[i]==0) break;
			if(f[i]==1) A++;
			if(f[i++]==2) B++;
		}
		printf("%d:%d\n",A,B);
		if(f[i]==0) break;
	}
}
还是WA
又发现AABB条件要改为>=>=
CPP
#include<iostream>
using std::string;using std::cin;using std::cout;
int abs(int a){
	if(a<0) return a*-1;
	return a;
}
int n;
int f[1000001];
int main(){
	char a;
	for(;cin>>a;){
		if(a=='E') break;
		if(a=='W') f[++n]=1;
		if(a=='L') f[++n]=2;
	}
	int i=1;
	while(1){
		int A=0,B=0;
		while(1){
			if((A>=11 || B>=11) && (abs(A-B)>1)) break;
			if(f[i]==0) break;
			if(f[i]==1) A++;
			if(f[i++]==2) B++;
		}
		printf("%d:%d\n",A,B);
		if(f[i]==0) break;
	}
	printf("\n");
	i=1;
	while(1){
		int A=0,B=0;
		while(1){
			if((A>=21 || B>=21) && (abs(A-B)>1)) break;
			if(f[i]==0) break;
			if(f[i]==1) A++;
			if(f[i++]==2) B++;
		}
		printf("%d:%d\n",A,B);
		if(f[i]==0) break;
	}
}

回复

1 条回复,欢迎继续交流。

正在加载回复...