两个好像是一样的
gets()最好不要在洛谷上用
by wuzhaoxin @ 2018-09-29 17:25:39
gets的代码那个getchar();不应该注释掉,但是有也是wa.
by sephiloss @ 2018-09-29 17:25:49
windows换行:'\n'
luogu:'\r'
by wuzhaoxin @ 2018-09-29 17:26:22
@[wuzhaoxin](/space/show?uid=70310)
getline 试了一发也是wa...
by sephiloss @ 2018-09-29 17:26:29
@[wuzhaoxin](/space/show?uid=70310)
手残粘错了,用getline也是不行的呀
```cpp
#include<cstdio>
#include<cstring>
#include<iostream>
#include<string>
using namespace std;
int main(){
int t;
scanf("%d",&t);
getchar();
char s[11111];
char tt[11];
int a=-1,b=-1,c=-1;
string p;
while(t--){
getline(cin,p);
strcpy(s,p.c_str());
// printf("%s\n",s);
if(s[0]=='a'||s[0]=='b'||s[0]=='c'){
sscanf(s+2,"%d %d",&b,&c);
a=s[0];
}else {
sscanf(s,"%d %d",&b,&c);
}
if(a=='a'){
printf("%d+%d=%d\n",b,c,c+b);
sprintf(s,"%d+%d=%d",b,c,c+b);
}else if(a=='b'){
printf("%d-%d=%d\n",b,c,b-c);
sprintf(s,"%d-%d=%d",b,c,b-c);
}else {
printf("%d*%d=%d\n",b,c,c*b);
sprintf(s,"%d-%d=%d",b,c,c*b);
}
printf("%d\n",strlen(s));
}
}
```
by sephiloss @ 2018-09-29 17:33:16
@[sephiloss](/space/show?uid=100579) 都8102年了,还用gets()。C++11不是早就罢黜了这个废物东西吗
by Ebola @ 2018-09-29 17:37:39
WA的原因是getchar()..用一句gets()替换getchar()就好了...but why?
by sephiloss @ 2018-09-29 17:44:14
@[sephiloss](/space/show?uid=100579) 可能是数据行末有空格
by jyttoby @ 2018-11-19 14:58:52
请问是gets的问题吗?
(如果我用 MBP clion C++)
by 粤若稽古 @ 2019-02-23 12:17:29