Saltyburst @ 2022-11-30 11:47:41
#include <stdio.h>
#include <string.h>
int lens(int a)
{
int i = 0;
for (i = 0; a != 0; a /= 10)
{
i++;
}
return i;
}
void main()
{
char op[51], temp[51];
int i, j, n, c, num[50][3] = { 0 };
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%s", &temp);
if (temp[0] == 'a' || temp[0] == 'b' || temp[0] == 'c')
{
op[i] = temp[0];
scanf("%d %d", &num[i][0], &num[i][1]);
}
else
{
op[i] = op[i - 1];
for (j = 0; j < strlen(temp); j++)
{
num[i][0] = num[i][0] * 10 + temp[j]-'0';
}
scanf("%d", &num[i][1]);
}
}
for (i = 0; i < n; i++)
{
c = 0;
if (op[i] == 'a')
{
printf("%d+%d=%d", num[i][0], num[i][1], num[i][0] + num[i][1]);
printf("\n%d", lens(num[i][0]) + lens(num[i][1]) + lens(num[i][0] + num[i][1]) + 2);
}
else if (op[i] == 'b')
{
printf("%d-%d=%d", num[i][0], num[i][1], num[i][0] - num[i][1]);
if (num[i][0] - num[i][1] < 0)
c++;
printf("\n%d", lens(num[i][0]) + lens(num[i][1]) + lens(num[i][0] - num[i][1]) + 2 + c);
}
else
{
printf("%d*%d=%d", num[i][0], num[i][1], num[i][0] * num[i][1]);
printf("\n%d", lens(num[i][0]) + lens(num[i][1]) + lens(num[i][0] * num[i][1]) + 2);
}
if (i != n - 1)
printf("\n");
}
}
有佬能指出怎么修改吗TAT
by Feng_Jing @ 2022-11-30 11:51:07
@Saltyburst
void main()
要用 int main(),CCF的比赛里好像都要求这个的
而且要加 return 0;
by _Nobody @ 2022-11-30 12:00:50
signed main()
同理
by Saltyburst @ 2022-11-30 13:17:01
@FengJingFJ2022 改后过了,感激不尽!