xjj2004 @ 2023-11-29 22:13:45
试过下载的测试点了,本机没看出问题,但还是过不了,救救孩子吧
#include<stdio.h>
#include<string.h>
int main()
{
int n;
int in1, in2, out;
char calculation[50];
char conculate = '\0';
scanf("%d", &n);
char ch[50][100];
getchar();
for (int i = 0; i < n; i++)
{
scanf("%[^\r\n]", ch[i]);
getchar();
}
for (int i = 0; i < n; i++)
{
if (ch[i][0] >= 'a' && ch[i][0] <= 'c')
sscanf(ch[i], "%c %d %d", &conculate, &in1, &in2);
else
sscanf(ch[i], "%d %d", &in1, &in2);
switch (conculate)
{
case 'a':
{
out = in1 + in2;
sprintf(calculation, "%d+%d=%d", in1, in2, out);
int l = strlen(calculation);
printf("%s\n%d\n", calculation, l);
break;
}
case 'b':
{
out = in1 - in2;
sprintf(calculation, "%d-%d=%d", in1, in2, out);
int l = strlen(calculation);
printf("%s\n%d\n", calculation, l);
break;
}
case 'c':
{
out = in1 * in2;
sprintf(calculation, "%d*%d=%d", in1, in2, out);
int l = strlen(calculation);
printf("%s\n%d\n", calculation, l);
break;
}
}
}
return 0;
}
by carloney2 @ 2023-12-02 13:03:44
#include<stdio.h>
#include<string.h>
int main()
{
int n;
int in1, in2, out;
char calculation[50];
char conculate = '\0';
scanf("%d", &n);
char ch[50][100];
int c;
while ((c = getchar()) != '\n' && c != EOF);
for (int i = 0; i < n; i++)
{
scanf("%[^\r\n]", ch[i]);
int c;
while ((c = getchar()) != '\n' && c != EOF);
}
for (int i = 0; i < n; i++)
{
if (ch[i][0] >= 'a' && ch[i][0] <= 'c')
sscanf(ch[i], "%c %d %d", &conculate, &in1, &in2);
else
sscanf(ch[i], "%d %d", &in1, &in2);
switch (conculate)
{
case 'a':
{
out = in1 + in2;
sprintf(calculation, "%d+%d=%d", in1, in2, out);
int l = strlen(calculation);
printf("%s\n%d\n", calculation, l);
break;
}
case 'b':
{
out = in1 - in2;
sprintf(calculation, "%d-%d=%d", in1, in2, out);
int l = strlen(calculation);
printf("%s\n%d\n", calculation, l);
break;
}
case 'c':
{
out = in1 * in2;
sprintf(calculation, "%d*%d=%d", in1, in2, out);
int l = strlen(calculation);
printf("%s\n%d\n", calculation, l);
break;
}
}
}
return 0;
}
getchar()是用于清除一个字符,直接改成清楚一整行就可以过了,这洛谷你输入enter实际上是\r\n,我也卡了好久,太痛苦了