zoukankan      html  css  js  c++  java
  • PAT:1017. A除以B (20) AC

    #include<stdio.h>
    #include<string.h>
    
    char n[1010];    //暂存输入的大整数字符串
    int num[1010];    //暂存可以运算的各位数字
    int cnt=0;      //记录数字个数
    int chu;      //除数
    int main()
    {
      scanf("%s %d",n,&chu);
      cnt=strlen(n);
      int yushu=0;            //本位不够除的时候,后位想此位借位
      for(int i=0 ; i<cnt ; ++i)      //每一位变成数字
        num[i]=n[i]-'0';
      bool first=0;            //【caution】记录第一个数字有没有输出,若第一个数字没有输出而要输出的是0,则不输出该0
      for(int i=0 ; i<cnt-1 ; ++i)    //处理前cnt-1位的数
      {
        int tmp=yushu*10+num[i];    //余数数放十位上,加上本位进行运算
        int out=tmp/chu;
        yushu=tmp%chu;
        if(out==0 && first==0)      //首位不输出0
          continue;
        printf("%d",out);
        first=1;            //首位已有非0输出,之后的0可以输出
      }
      //处理最后一位
      int tmp=yushu*10+num[cnt-1];
      printf("%d %d
    ",tmp/chu,tmp%chu);
      return 0;
    }
  • 相关阅读:
    FileWatcher
    virtual table(有180个评论)
    this 指针
    docker -ce(社区免费版)
    vue-cli
    CAP理论、BASE理论
    B+树和LSM存储引擎代表树和B-树
    CPU高速缓存
    Python&基础环境搭建
    二叉树
  • 原文地址:https://www.cnblogs.com/Evence/p/4318763.html
Copyright © 2011-2022 走看看