21比分局就不可以了,2501行的数据对不上,究竟是哪里出错了呢,求大佬解惑
查看原帖
21比分局就不可以了,2501行的数据对不上,究竟是哪里出错了呢,求大佬解惑
576475
yanzhimin楼主2022/7/6 09:20
#include <stdio.h>
#include <string.h>
char arr[100];
int small_score[3],big_score[3];
char ans1[2505][10],ans2[2505][10];
int top = 0,top2 = 0;
int main()
{
	int flag = 1,sum = 0,time = 0;
	do{
		//TODO
		scanf("%s",arr);
		int n = strlen(arr);
		time++;
		for(int i = 0; i < n;i++)
		{
			if(arr[i] == 'E')
			{
				flag = 0; break;
			}
			if(arr[i] == 'W')
			{
				small_score[1]++;
				big_score[1]++;
				sum++;
			}
			else if(arr[i] == 'L')
			{
				small_score[2]++;
				big_score[2]++;
			}
			if((small_score[1] >= 11 || small_score[2] >= 11) && ((small_score[1] >= small_score[2] + 2)||(small_score[2] >= small_score[1] +2)))
			{
				snprintf(ans1[top++],10,"%d:%d\n",small_score[1],small_score[2]);
				small_score[1] = 0;
				small_score[2] = 0;
			}
			if((big_score[1] >= 21 || big_score[2]>= 21) && ((big_score[1] >= big_score[2]+2)||(big_score[2]>=big_score[1]+2)))
			{
				if(time == 1655)
				{
					flag = 1;
				}
				snprintf(ans2[top2++],10,"%d:%d\n",big_score[1],big_score[2]);
				big_score[1] = 0;
				big_score[2] = 0;
			}
		}
	}while(flag);
//	printf("%d\n\n\n\n\n",sum);
	snprintf(ans1[top++],10,"%d:%d\n",small_score[1],small_score[2]);
	snprintf(ans2[top2++],10,"%d:%d\n",big_score[1],big_score[2]);
	for(int i = 0; i < top;i++)
	{
		printf("%s",ans1[i]);
	}
	printf("\n");
	for(int i = 0; i < top2;i++)
	{
		printf("%s",ans2[i]);
	}
	return 0;
}

代码中的time,sum都是当时为了调试快速设置的断点量,方便在那里停住,结果发现在1655行的时候出现bug了

2022/7/6 09:20
加载中...