zoukankan      html  css  js  c++  java
  • 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]='';
    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
    ");
    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("
    ");}}
    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
  • 相关阅读:
    java 基础中的字符串
    Java中的基本数据类型
    js 实现焦点图轮播效果和 jquery实现焦点图轮播效果
    Html中 value 和 name 属性的作用
    分别用js 和 html/css实现下拉菜单特效
    divide-conquer-combine(4.1 from the introduction to algorithm)
    1063. Set Similarity (25)
    1085. Perfect Sequence (25)
    1015. Reversible Primes (20)
    1057. Stack (30)
  • 原文地址:https://www.cnblogs.com/gznb/p/11213703.html
Copyright © 2011-2022 走看看