社区讨论
为什么交上去全都WA
P1957口算练习题参与者 2已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @lo19hgm5
- 此快照首次捕获于
- 2023/10/22 17:23 2 年前
- 此快照最后确认于
- 2023/11/02 17:25 2 年前
为什么本地可以过,洛谷云IDE也可以过,交上去全都WA啊。。。之前别人说是getline搞的鬼,现在改成了fgets还是不行
我的代码:
CPP#include <bits/stdc++.h>
using namespace std;
int n, res, num[2], opt_num;
char opt_char, _in[100], _out[100];
int main()
{
// 输入
scanf("%d", &n);
getchar();
// 处理
for (int i = 0; i < n; i++)
{
fgets(_in, 100, stdin);
// new opt
// and input numbers from string (_in and _out)
if (_in[0] >= 'a')
{
opt_num = _in[0] - 'a' + 1;
sscanf(_in + 2, "%d%d", &num[0], &num[1]);
}
else
{
sscanf(_in, "%d%d", &num[0], &num[1]);
}
// compute result
switch (opt_num)
{
case 1:
opt_char = '+', res = num[0] + num[1];
break;
case 2:
opt_char = '-', res = num[0] - num[1];
break;
case 3:
opt_char = '*', res = num[0] * num[1];
break;
default:
break;
}
// output
sprintf(_out, "%d%c%d=%d", num[0], opt_char, num[1], res);
printf("%s\n%d\n", _out, strlen(_out));
}
return 0;
}
到底是出了什么问题啊。。。
回复
共 3 条回复,欢迎继续交流。
正在加载回复...