wayc04 @ 2022-12-27 23:15:45
#include<stdio.h>
#include<string.h>
int main()
{
int i;scanf("%d",&i);
char leixing;
char str[1000];int a=0,a1,b=0,b1;int x;int c;int changdu=0;
for(int n=0;n<i;n++)
{
a=0;b=0;changdu=0;
scanf(" %[^\n]",str);
if(str[0]>='a')
{
leixing=str[0];
for(x=2;str[x]!=' ';x++)
{
a1=str[x]-'0';
a=a*10+a1;
changdu++;
}
for(x=x+1;str[x]!='\0';x++)
{
b1=str[x]-'0';
b=b*10+b1;changdu++;
}
}
else
{
for(x=0;str[x]!=' ';x++)
{
a1=str[x]-'0';
a=a*10+a1;changdu++;
}
for(x=x+1;str[x]!='\0';x++)
{
b1=str[x]-'0';
b=b*10+b1;changdu++;
}
}
if(leixing=='a')
{
c=a+b;int c1=c;while(c1>0){c1/=10;changdu++;
}
printf("%d+%d=%d\n%d\n",a,b,c,changdu+2);
}
if(leixing=='c')
{
c=a*b;int c1=c;while(c1>0){c1/=10;changdu++;
}
printf("%d*%d=%d\n%d\n",a,b,c,changdu+2);
}
if(leixing=='b')
{
c=a-b;int c1=c;
if(c>0)
{
while(c1>0){c1/=10;changdu++;
}printf("%d-%d=%d\n%d\n",a,b,c,changdu+2);
}
else if(c==0)
{
printf("%d-%d=%d\n%d\n",a,b,c,changdu+3);
}
else
{
c1=-c1;
while(c1>0){c1/=10;changdu++;
}printf("%d-%d=%d\n%d\n",a,b,c,changdu+3);
}
}
}
}
by telankesi @ 2022-12-28 08:43:43
if(str[0]>='0'&&str[0]<='9')试一试
if(str[0]>='a')
{
leixing=str[0];
for(x=2;str[x]!=' ';x++)
{
a1=str[x]-'0';
a=a*10+a1;
changdu++;
}
for(x=x+1;str[x]!='\0';x++)
{
b1=str[x]-'0';
b=b*10+b1;changdu++;
}
}
by wayc04 @ 2022-12-28 10:45:33
@telankesi 但是这好像没用啊
by AlexFad @ 2023-04-28 20:55:02
应该是 scanf(" %[^\n]",str); 的问题,用洛谷在线IDE,这样是输入不了的
by AlexFad @ 2023-04-28 21:01:03
改成这样就行了
scanf("%*[\r\n]%[^\n]",s);