MC_dream_tsr @ 2024-08-21 16:25:05
不太理解怎么输入求解(别发AC本题的代码哈,最开始想用getline,然后用高精,但太肝了没做出来
by best_lover @ 2024-08-21 16:27:10
您的意思是输入
1+1=
输出
1+1=2
是我理解的这样吗/yiw
by best_lover @ 2024-08-21 16:27:20
@MC_dream_tsr
by MC_dream_tsr @ 2024-08-21 16:35:49
@best_lover e.....接着的 i 行为需要输入的算式,每行可能有三个数据或两个数据。
如果我表述不当,您可以看下这道题原题
by best_lover @ 2024-08-21 16:41:16
@MC_dream_tsr 读入一个
cin >> s;
if(s >= '0' && s <= '9'){
for(int i = 0; i < s.size(); i++)
a = a * 10 + (s[i] - '0');
cin >> b;
}
else {
cin >> a >> b;
}
by best_lover @ 2024-08-21 16:41:31
@best_lover 我还没试过不保证正确性()
by MC_dream_tsr @ 2024-08-21 16:47:39
@best_lover NB,很妙的数据类型转换(谢谢
by guoyanwei120223 @ 2024-08-24 16:58:09
@MC_dream_tsr AC
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,n;
char last,s[20],ans[20];
scanf("%d",&n);
getchar();
while(n--)
{
fgets(s,sizeof(s),stdin);
if(s[0]=='a'||s[0]=='b'||s[0]=='c')
{
last=s[0];
s[0]=' ';
}
sscanf(s,"%d %d",&a,&b);
switch(last)
{
case 'a':c=a+b;sprintf(ans,"%d+%d=%d",a,b,c);break;
case 'b':c=a-b;sprintf(ans,"%d-%d=%d",a,b,c);break;
case 'c':c=a*b;sprintf(ans,"%d*%d=%d",a,b,c);break;
}
printf("%s\n%d\n",ans,strlen(ans));
}
}
by MC_dream_tsr @ 2024-08-24 16:59:36
@guoyanwei120223 谢谢(我已经AC了
by guoyanwei120223 @ 2024-08-24 17:01:59
@MC_dream_tsr 好吧