当前位置:网站首页>P1042 table tennis (simulation)

P1042 table tennis (simulation)

2021-08-10 08:04:09 wx6110fa547fd20

P1042 Table Tennis ( simulation )

  Subject portal

The question : Find... For several lines of string 11 The system and 21 All scores under the scoring system are output .

Ideas : use getchar Read in , Record while reading , Yes 11 In terms of score system , If one party's score is greater than or equal to 11 And the difference between the two scores is greater than or equal to 2 Then record the score , Then the initialization state continues . Attention to details :—detail1—: After that, you need to record the final score , such as 1:2 There's no match yet . —detail2— : 0:0 Also count the score .
The input EWLWLWL To export
0:0
0:0

AC Code

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
struct p{
	int x,y;
}e[N],f[N];
int main(){
	char c;
	int a[2]={},b[2]={},cnt[2]={},k1=0,k2=0;
	while((c=getchar())!='E'){
		cnt[0]++,cnt[1]++;
		if(c=='W'){
			a[0]++,b[0]++;
		}
		else if(c=='L'){
			a[1]++,b[1]++;
		}
		if((a[0]>=11||a[1]>=11)&&abs(a[0]-a[1])>=2) e[++k1].x=a[0],e[k1].y=a[1],cnt[0]=a[0]=a[1]=0;
		if((b[0]>=21||b[1]>=21)&&abs(b[0]-b[1])>=2) f[++k2].x=b[0],f[k2].y=b[1],cnt[1]=b[0]=b[1]=0;
	}
	 e[++k1].x=a[0],e[k1].y=a[1];
	 f[++k2].x=b[0],f[k2].y=b[1];
	for(int i=1;i<=k1;i++)
		printf("%d:%d\n",e[i].x,e[i].y);
	puts("");
	for(int i=1;i<=k2;i++)
		printf("%d:%d\n",f[i].x,f[i].y);
		return 0;
}

      
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.

版权声明
本文为[wx6110fa547fd20]所创,转载请带上原文链接,感谢
https://chowdera.com/2021/08/20210810080205540c.html

随机推荐