Big Number
作者:互联网
Big Number
Problem Description
As we know, Big Number is always troublesome. But it's really important in our ACM. And today, your task is to write a program to calculate A mod B.To make the problem easier, I promise that B will be smaller than 100000.
Is it too hard? No, I work it out in 10 minutes, and my program contains less than 25 lines.
Input
The input contains several test cases. Each test case consists of two positive integers A and B. The length of A will not exceed 1000, and B will be smaller than 100000. Process to the end of file.Output
For each test case, you have to ouput the result of A mod B.Sample Input
2 3 12 7 152455856554521 3250
Sample Output
2 5 1521
1 #include<stdio.h> 2 #include<string.h> 3 int b1,b2,b3,a1[110000],a2[110000],n; 4 char str1[110000],str2[110000],str3[110000],*p; 5 int main() 6 { 7 void fun(); 8 p=str1; 9 int i,j,k,x=0,c; 10 while( gets(str1)) 11 { 12 for(i=0;i<11000;i++) 13 { if(str1[i]==' ') 14 {str1[i]='\0'; 15 strcpy(str2,p+i+1);break;}} 16 17 18 b1=strlen(str1); 19 b2=strlen(str2); 20 if(b1<b2){puts(str1); } 21 else if(b1==b2&&(strcmp(str1,str2)<0)){puts(str1);} 22 else 23 {int h=b2-1; 24 for(i=b2-1;i>=0;i--) 25 a1[b2-i-1]=str1[i]-'0'; 26 for(i=b2-1;i>=0;i--) 27 a2[b2-i-1]=str2[i]-'0'; 28 for(j=0;j<=b1-b2;j++) 29 { 30 fun(); 31 h++; 32 for(i=b2;i>0;i--) 33 a1[i]=a1[i-1]; 34 a1[0]=str1[h]-'0'; 35 } 36 k=b1-b2+1; 37 for(i=1;i<=k;i++) 38 c=c+a1[i]; 39 if(c==0) 40 printf("0\n"); 41 else { 42 while(1) 43 { 44 if(a1[k]==0)k--; 45 else break; 46 } 47 for(i=k;i>0;i--) 48 printf("%d",a1[i]); 49 printf("\n");}} 50 for(i=0;i<11000;i++) 51 { str3[i]=0;a1[i]=0;a2[i]=0;}} 52 return 0; 53 } 54 void fun() 55 { int i,j,c; 56 for(;;) 57 {for(i=b2-1;i>=0;i--) 58 str3[b2-i-1]=a1[i]+'0'; 59 str3[i]=0; 60 if((strcmp(str3,str2)>=0)||a1[b2]>0) 61 { 62 for(i=0;i<=b2;i++) 63 { 64 if(a1[i]<a2[i]) 65 { a1[i]=a1[i]+10-a2[i];a1[i+1]=a1[i+1]-1; 66 } 67 else a1[i]=a1[i]-a2[i]; 68 } 69 } 70 else break; 71 } 72 }View Code
标签:110000,str3,Big,str1,Number,a1,b2,than 来源: https://www.cnblogs.com/gznb/p/11213703.html