P1042 [NOIP2003 普及组] 乒乓球

Emmmmmmmmm,这个题如果你对乒乓球制度不了解就很坑。。。。

1、以11分制为例,赢则必须要两者分差大于等于2且赢的一方要至少有11分,就是说赢的不是一定就恰好11分的,有可能此时,12分,13分。。。。

2、还有就是0:0也要输出

#include<bits/stdc++.h> 
using namespace std;
//int _max=-0x7fffffff;
typedef struct node
{
	int X;	
	int Y;	
}node;//输出即为X:Y
node A[10000];
node B[10000];
int _count1=0;
int _count2=0;
int main()
{
	char S[63000];
	int score1=0;
	int score2=0;
	int _score1=0;
	int _score2=0;
	int i; 
	while(scanf("%c",&S[i])&&S[i]!='E')
	{
			if(S[i]=='W')
			{
				score1++;
				_score1++;	
			}
			
			if(S[i]=='L')
			{
				score2++;
				_score2++;
			}
			if(abs(score1-score2)>=2&&(score1>=11||score2>=11))  //if(abs(score1-score2)>=2&&(score1==11||score2==11))  
			{
				A[_count1].X=score1;
				A[_count1++].Y=score2; 
				score1=0;
				score2=0;
			} 
			if(abs(_score1-_score2)>=2&&(_score1>=21||_score2>=21))
			{
				B[_count2].X=_score1;
				B[_count2++].Y=_score2; 
				_score1=0;
				_score2=0;
			}	
		i++;
	}
	for(int i=0;i<_count1;i++)
		printf("%d:%d\n",A[i].X,A[i].Y);
	//if(score1!=0||score2!=0)
		printf("%d:%d\n",score1,score2);
	printf("\n");
	for(int i=0;i<_count2;i++)
		printf("%d:%d\n",B[i].X,B[i].Y);
	//if(_score1!=0||_score2!=0)
		printf("%d:%d\n",_score1,_score2);
	return 0;	
}

第二个:

#include<bits/stdc++.h> 
using namespace std;
//int _max=-0x7fffffff;
typedef struct node
{
	int X;	
	int Y;	
}node;//输出即为X:Y
node A[10000];
node B[10000];
int _count1=0;
int _count2=0;
int main()
{
	char S[30];
	int score1=0;
	int score2=0;
	int _score1=0;
	int _score2=0;
	int FLAG=1;
	while(FLAG&&scanf("%s",S)!=EOF) //while(scanf("%s",S)&&FLAG)
	{
		int len=strlen(S);
		for(int i=0;i<len;i++)
		{
			if(S[i]=='W')
			{
				score1++;
				_score1++;	
			}
			if(S[i]=='L')
			{
				score2++;
				_score2++;
			}
			if(abs(score1-score2)>=2&&(score1>=11||score2>=11))  //之前写的错的:if(abs(score1-score2)>=2&&(score1==11||score2==11))  
			{
				A[_count1].X=score1;
				A[_count1++].Y=score2; 
				score1=0;
				score2=0;
			} 
			if(abs(_score1-_score2)>=2&&(_score1>=21||_score2>=21))
			{
				B[_count2].X=_score1;
				B[_count2++].Y=_score2; 
				_score1=0;
				_score2=0;
			}	
			if(S[i]=='E')
			{
			FLAG=0;
			break;	
			}
	   }
	}
	for(int i=0;i<_count1;i++)
		printf("%d:%d\n",A[i].X,A[i].Y);
	//if(score1!=0||score2!=0)
		printf("%d:%d\n",score1,score2);
	printf("\n");
	for(int i=0;i<_count2;i++)
		printf("%d:%d\n",B[i].X,B[i].Y);
	//if(_score1!=0||_score2!=0)
		printf("%d:%d\n",_score1,_score2);
	return 0;	
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值