sunxiaofan @ 2021-10-16 10:44:06
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
inline int read()
{
int a;
char c;
c=getchar();
while(c>='0'&&c<='9')
{
a=a*10+c-'0';
c=getchar();
}
return a;
}
int n,l,num1,num2,x;
char a[150],c,b[150];
int main()
{
n=read();
for(int i=1;i<=n;i++)
{
scanf("%s",a);
num1=0;
num2=0;
if(a[0]>='a'&&a[0]<='c')
{
c=a[0];
scanf("%s%s",a,b);
}
else
{
scanf("%s",b);
}
l=2+strlen(a)+strlen(b);
x=strlen(a);
for(int i=0;i<x;i++)
{
num1=num1*10+a[i]-'0';
}
x=strlen(b);
for(int i=0;i<x;i++)
{
num2=num2*10+b[i]-'0';
}
printf("%d",num1);
if(c=='a')printf("+%d=",num2);
else if(c=='b')
printf("-%d=",num2);
else
printf("*%d=",num2);
if(c=='a')
num1+=num2;
else if(c=='b')
num1-=num2;
else
num1*=num2;
printf("%d\n",num1);
if(num1<=0)l++;
while(num1)
{
num1/=10;
l++;
}
printf("%d\n",l);
}
}
代码如上,请求大佬帮助
by sunxiaofan @ 2021-10-16 10:52:01
没事了,找到错误了
by sunxiaofan @ 2021-10-16 10:52:36
变量为i的循环里又出现了变量i
by sunxiaofan @ 2021-10-16 10:57:34
快读也出问题了