Bruce225 @ 2024-05-05 19:17:29
代码如下:
#include "iostream"
#include "string.h"
#include "stdio.h"
#include "math.h"
using namespace std;
int digit(int num)
{
int ss=0;
if (num==0) return 1;
while (num!=0)
{
num/=10;
ss++;
}
return ss;
}
int main()
{
int n;
char s[100],ch,ch0;
scanf("%d",&n);
scanf("%c",&ch0);
for (int i=1;i<=n;i++)
{
gets(s);
int flag,num1=0,num2=0;
if (s[0]>='a'&&s[0]<='c')
{
ch=s[0];
for (int j=2;j<=strlen(s)-1;j++)
if (s[j]==' ') flag=j;
for (int j=flag-1;j>=2;j--)
num1+=(s[j]-'0')*pow(float(10),float(flag-j-1));
for (int j=strlen(s)-1;j>=flag+1;j--)
num2+=(s[j]-'0')*pow(float(10),float(strlen(s)-1-j));
}
else
{
for (int j=0;j<=strlen(s)-1;j++)
if (s[j]==' ') flag=j;
for (int j=flag-1;j>=0;j--)
num1+=(s[j]-'0')*pow(float(10),float(flag-j-1));
for (int j=strlen(s)-1;j>=flag+1;j--)
num2+=(s[j]-'0')*pow(float(10),float(strlen(s)-1-j));
}
switch (ch)
{
case 'a':
{
int t,sum=num1+num2;
t=digit(num1)+digit(num2)+digit(sum);
printf("%d+%d=%d\n",num1,num2,sum);
printf("%d\n",t+2);
break;
}
case 'b':
{
int t,sum=num1-num2;
t=digit(num1)+digit(num2)+digit(sum)+(sum<0);
printf("%d-%d=%d\n",num1,num2,sum);
printf("%d\n",t+2);
break;
}
case 'c':
{
int t,sum=num1*num2;
t=digit(num1)+digit(num2)+digit(sum);
printf("%d*%d=%d\n",num1,num2,sum);
printf("%d\n",t+2);
break;
}
}
}
return 0;
}
不知道为什么,所有数据点都RE了,在本地vs上可以正常运行,下载了第一个数据点运行结果也是对的,求助大佬们ORZ
by SugarKite @ 2024-05-05 19:24:07
digit是c++关键词,换一个名字就好了
by Bruce225 @ 2024-06-18 22:43:16
@Tzy090420 好的,谢谢!