zoukankan      html  css  js  c++  java
  • 两个大整数的除法

    两个大整数的除法 

    Problem Description

    计算两个大整数的商

    Input

    共2行,每行一个大整数

    Output

    共1行,表示两个大整数的商(整数部分)

    Sample Input

    100
    3

    Sample Output

    33
     1 #include<stdio.h>
     2 #include<string.h>
     3 int b1,b2,a3[100],a1[100],a2[100];
     4 char str1[100],str2[100],str3[100];
     5 int main()
     6 { int fun();
     7     int i,j,k,x=0;
     8     gets(str1);gets(str2);
     9     b1=strlen(str1);
    10     b2=strlen(str2);
    11     int h=b2-1;
    12     for(i=b2-1;i>=0;i--)
    13       a1[b2-i-1]=str1[i]-'0';
    14     for(i=b2-1;i>=0;i--)
    15       a2[b2-i-1]=str2[i]-'0';
    16     for(j=0;j<=b1-b2;j++)
    17     {
    18       a3[j]=fun();
    19        h++;
    20            for(i=b2;i>0;i--)
    21            a1[i]=a1[i-1];
    22            a1[0]=str1[h]-'0';
    23     }
    24 if(a3[0]==0);
    25 else printf("%d",a3[0]);
    26 for(i=1;i<=b1-b2;i++)
    27 printf("%d",a3[i]);
    28 printf("
    ");
    29 return 0;
    30 }
    31 int fun()
    32 {    int i,j,c,d=0;
    33 for(;;)
    34  {for(i=b2-1;i>=0;i--)
    35       str3[b2-i-1]=a1[i]+'0';
    36       str3[i]=0;
    37       if((strcmp(str3,str2)>=0)||a1[b2]>0)
    38   { 
    39  for(i=0;i<=b2;i++)
    40    {
    41          if(a1[i]<a2[i]) 
    42        { a1[i]=a1[i]+10-a2[i];a1[i+1]=a1[i+1]-1;
    43        }
    44         else a1[i]=a1[i]-a2[i];
    45     }
    46     d++;
    47  }
    48    else break;
    49  }
    50  return d;
    51 }
    View Code
  • 相关阅读:
    强连通分量(Kosaraju)
    拓扑排序
    树状数组BIT
    差分
    RMQ(ST表)
    LCA(Tarjan)
    LCA(ST倍增)
    海亮SC2019 树上数数(转载)
    海亮SC
    【十二省联考2019】异或粽子/可持久化01trie
  • 原文地址:https://www.cnblogs.com/gznb/p/11213722.html
Copyright © 2011-2022 走看看