明明自己测试的时候没发现什么问题:(
#include <stdio.h>
#include <math.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
struct game
{
int p1;
int p2;
bool ie;
};
int main(void)
{
char x[62501];
struct game l[5700];
struct game l2[5700];
int ct1 = 0;
while(ct1 < 5700)
{
l2[ct1].p2 = 0;
l2[ct1].p1 = 0;
l[ct1].p2 = 0;
l[ct1].p1 = 0;
l[ct1].ie = false;
l2[ct1].ie = false;
ct1++;
}
x[62500] = (char)0;
int count = 0;
bool flag = false;
int t = 0;
while(1)
{
//printf("%d\n",count);
t = (char)getchar();
if(count == 0 && t == 'E')
{
flag = true;
break;
}
if(t == 'E') break;
x[count] = ((t == 'E') ? 0 : t);
if(x[count] != '\n')
count++;
}
if(flag)
{
printf("0:0\n\n0:0\n");
return 0;
}
int call = 0;
int cst = 0;
int sgc = 0;
while(true)
{
if(x[call] == 'W')
l[sgc].p1++;
else if(x[call] == 'L')
l[sgc].p2++;
cst++;
//printf("%d %d\n",l[sgc].p1,l[sgc].p2);
if(cst == 11)
{
cst = 0;
sgc++;
}
call++;
if(call == count)
{
if(l[sgc].p1 == l[sgc].p2 && l[sgc].p1 == 0)
l[sgc - 1].ie = true;
else
l[sgc].ie = true;
break;
}
}
call = 0;
sgc = 0;
cst = 0;
while(true)
{
if(x[call] == 'W')
l2[sgc].p1++;
else if(x[call] == 'L')
l2[sgc].p2++;
cst++;
if(cst == 21)
{
cst = 0;
sgc++;
}
call++;
if(call == count)
{
if(l2[sgc].p1 == l2[sgc].p2 && l2[sgc].p1 == 0)
l2[sgc - 1].ie = true;
else
l2[sgc].ie = true;
break;
}
}
sgc = 0;
while(true)
{
printf("%d:%d\n",l[sgc].p1,l[sgc].p2);
if(l[sgc].ie)
{
if(l[sgc].p1 + l[sgc].p2 == 11)
{
printf("0:0\n");
}
break;
}
sgc++;
}
puts("");
sgc = 0;
while(true)
{
printf("%d:%d\n",l2[sgc].p1,l2[sgc].p2);
if(l2[sgc].ie)
{
if(l[sgc].p1 + l[sgc].p2 == 21)
{
printf("0:0\n");
}
break;
}
sgc++;
}
}
附splint检查报告(可能没什么用 囧)
Splint 3.1.2a --- May 25 2020
main.c: (in function main)
main.c:32:11: Test expression for while not boolean, type int: 1
Test expression type is not boolean or int. (Use -predboolint to inhibit
warning)
main.c:35:9: Assignment of char to int: t = (char)getchar()
To make char and int types equivalent, use +charint.
main.c:36:26: Operands of == have incompatible types (int, char): t == 'E'
A character constant is used as an int. Use +charintliteral to allow
character constants to be used as ints. (This is safe since the actual type
of a char constant is int.)
main.c:41:12: Operands of == have incompatible types (int, char): t == 'E'
main.c:42:22: Operands of == have incompatible types (int, char): t == 'E'
main.c:42:9: Assignment of int to char: x[count] = ((t == 'E') ? 0 : t)
main.c:57:15: Value l[] used before definition
An rvalue is used that may not be initialized to a value on some execution
path. (Use -usedef to inhibit warning)
main.c:59:15: Value l[] used before definition
main.c:70:18: Value l[] used before definition
main.c:70:31: Field l[].p2 used before definition
main.c:83:15: Value l2[] used before definition
main.c:85:15: Value l2[] used before definition
main.c:95:18: Value l2[] used before definition
main.c:95:32: Field l2[].p2 used before definition
main.c:105:26: Value l[] used before definition
main.c:105:26: Passed storage l[].p1 not completely defined (l[].p1 is
undefined): printf (..., l[sgc].p1)
Storage derivable from a parameter, return value or global is not defined.
Use /*@out@*/ to denote passed or returned storage which need not be defined.
(Use -compdef to inhibit warning)
main.c:105:36: Field l[].p2 used before definition
main.c:116:5: Return value (type int) ignored: puts("")
Result returned by function call is not used. If this is intended, can cast
result to (void) to eliminate message. (Use -retvalint to inhibit warning)
main.c:120:26: Value l2[] used before definition
main.c:120:26: Passed storage l2[].p1 not completely defined (l2[].p1 is
undefined): printf (..., l2[sgc].p1)
main.c:120:37: Field l2[].p2 used before definition
main.c:123:16: Value l[] used before definition
main.c:123:28: Field l[].p2 used before definition
main.c:131:2: Path with no return in function declared to return int
There is a path through a function declared to return a value on which there
is no return statement. This means the execution may fall through without
returning a meaningful result to the caller. (Use -noret to inhibit warning)
Finished checking --- 24 code warnings