做了A+B Problem,A/B Problem不是什么问题了吧!
110 / 100 99 % 10 2147483647 / 2147483647 2147483646 % 2147483647
1 9 1 2147483646
#include<stdio.h>
#include<string.h>
char a[10010]; //为避免错误,数组最好开大点,刚开始开到1000010
int sum[10010];
int main()
{
char ch;
int i,j,t,B,len;
while(~scanf("%s",a))
{
while(1)
{
ch=getchar();
if(ch=='/'||ch=='%')
break;
}
scanf("%d",&B);
memset(sum,0,sizeof(sum));
t=0;i=0;j=0;len=strlen(a);
while(i<len)
{
t=t*10+a[i++]-'0';
if(t==0)
sum[j++]=0;
else if(j!=0)
{ //printf("***\n");
sum[j++]=t/B;
t=t%B;
}
else if(t>=B) //控制商的最高位不为0
{
sum[j++]=t/B;
t%=B;
}
}
if(ch=='%')
{
printf("%d\n",t%B);
continue;
}
for(i=0;i<j-1;++i)
if(sum[i])
break;
for(;i<j;++i)
printf("%d",sum[i]);
printf("\n");
}
return 0;
}
终于能过了!!!!!!!!!!!!!!
一些特殊测试数据:
1000 / 1=1000;
10100 / 2=50500;
原文:http://blog.csdn.net/qq_18062811/article/details/39078211