spindrift @ 2023-11-17 21:03:52
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
int main()
{
int n;
char lastsign;
char s[30];
char s2[30];
int a, b;
cin >> n;
getchar();
getchar();
int sum;
while (n-- > 0) {
fgets(s, sizeof(s), stdin);
if (s[0] == 'a' || s[0] == 'b' || s[0] == 'c') {
lastsign = s[0]; s[0] = ' ';//为了使下面的scanf能够正常输入;
}
sscanf(s, "%d %d", &a, &b);
switch (lastsign) {
case 'a':
sum = a + b;
sprintf(s2, "%d+%d=%d",a,b, sum); break;//break别忘了
case 'b':
sum = a - b;
sprintf(s2, "%d-%d=%d", a, b, sum); break;
case 'c':
sum = a * b;
sprintf(s2, "%d*%d=%d", a, b, sum); break;
}
printf("%s\n", s2);
cout << strlen(s2) << endl;
}
return 0;
}
好像真的没什么问题啊 要疯了
by spindrift @ 2023-11-17 21:06:34
我最上面多打了一个getchar(),忽略了就行了
by spindrift @ 2023-11-17 21:20:04
兄弟们解决了,是getchar()的问题 我换成了scanf("%d\n"就正确了 啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊折磨我一小时 到底是为啥?
by 17345044098pr @ 2023-11-19 11:17:03
@spindrift 我也卡在这里,看见你说的,我改了getchar,然后就过了,为什么啊啊啊啊啊啊啊啊啊
by spindrift @ 2023-11-19 12:11:04
@17345044098pr 不知道。。笑死我了,咱俩一起疯吧