asdf2021 @ 2024-11-27 00:38:33
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
typedef struct competitionResult{
int player1Score;
int player2Score;
}CompetitionResult;//结构体存比赛双方信息
//初始化为0
void initCompetitionResult(CompetitionResult *res){
res->player1Score=0;
res->player2Score=0;
}
//11分制
void matchResult11(CompetitionResult *res,char points[][26],int m){
m++;//此处输入m为行数的下标
for(int i=0;i<m;i++){
int len=strlen(points[i]);//每一行的信息个数
for(int j=0;j<len;j++){
if((res->player1Score>=11||res->player2Score>=11)&&abs(res->player1Score-res->player2Score)>=2){//如果其中一方大于等于11并且分差大于等于2
printf("%d:%d\n",res->player1Score,res->player2Score);//输出并且初始化
initCompetitionResult(res);
}
if(points[i][j]=='W') res->player1Score++;//W则左边++
else if(points[i][j]=='L') res->player2Score++;//L则右边++
else{//等于E就输出并初始化
printf("%d:%d",res->player1Score,res->player2Score);
initCompetitionResult(res);
return ;
}
}
}
}
//21分制同上
void matchResult21(CompetitionResult *res,char points[][26],int m){
m++;
for(int i=0;i<m;i++){
int len=strlen(points[i]);
for(int j=0;j<len;j++){
if((res->player1Score>=21||res->player2Score>=21)&&abs(res->player1Score-res->player2Score)>=2){
printf("%d:%d\n",res->player1Score,res->player2Score);
initCompetitionResult(res);
}
if(points[i][j]=='W') res->player1Score++;
else if(points[i][j]=='L') res->player2Score++;
else{
printf("%d:%d",res->player1Score,res->player2Score);
initCompetitionResult(res);
return ;
}
}
}
}
int main(){
char points[2600][26];//存比赛信息
int m=-1;
do{
m++;//从第0行开始输入
gets(points[m]);
}while(strchr(points[m],'E')==NULL);
CompetitionResult res;
initCompetitionResult(&res);
matchResult11(&res,points,m);//11分制输出
printf("\n\n");
matchResult21(&res,points,m);//21分制输出
return 0;
}
by 11514zbs @ 2024-11-27 06:36:58
@asdf2021
你这代码太繁琐了吧……
#include <cstdio>
long long AW11, BW11, AW21, BW21, A21[5685], B21[5685], num;
char x;
int main()
{
scanf("%c", &x);
while (x != 'E')
{
if (x == 'W')
{
AW11++;
AW21++;
}
if (x == 'L')
{
BW11++;
BW21++;
}
if ((AW11 >= 11 && AW11 - BW11 >= 2) || (BW11 >= 11 && BW11 - AW11 >= 2))
{
printf("%lld:%lld\n", AW11, BW11);
AW11 = 0;
BW11 = 0;
}
if ((AW21 >= 21 && AW21 - BW21 >= 2) || (BW21 >= 21 && BW21 - AW21 >= 2))
{
A21[num] = AW21;
B21[num] = BW21;
AW21 = 0;
BW21 = 0;
num++;
}
scanf("%c", &x);
}
printf("%lld:%lld\n\n", AW11, BW11);
for (int i = 0; i < num; i++)
{
printf("%lld:%lld\n", A21[i], B21[i]);
}
printf("%lld:%lld\n", AW21, BW21);
return 0;
}
by TallBanana @ 2024-11-27 07:26:58
@asdf2021
你不会是用AI做的吧。。
by asdf2021 @ 2024-11-27 10:17:20
@TallBanana@TallBanana 自己写的TT只是,前两天学了结构体于是
by asdf2021 @ 2024-11-27 10:36:54
@11514zbs是的TT(因为刚学了结构体想着用一下) 你这个我看懂了感谢Thanks♪(・ω・)ノ 我想知道我的代码为什么过不了TT因为我下载了一个测试数据一个个对了一遍,发现我的输出全都是一样的啊