zoukankan      html  css  js  c++  java
  • 1017. A除以B

     题目截图:

    思路:

      高精度与低精度的除法,详解请看另一篇博客

    代码:

     1 /*
     2     1017. A除以B
     3 */
     4 
     5 #include <stdio.h>
     6 #include <string.h>
     7 #include <math.h>
     8 #include <stdlib.h>
     9 #include <time.h>
    10 
    11 #define maxn 1002
    12 typedef struct {
    13     int d[1001];    // 存储大整数 
    14     int end;        // 末位位置 
    15     int begin;        // 首位位置 
    16 } bign; 
    17 
    18 int main() {
    19     bign a;
    20     int b, i;
    21     char str[maxn];
    22     scanf("%s %d", str, &b);
    23     for(i=0; i<strlen(str); ++i) {    // 将字符串传换成大整数 
    24         a.d[i] = str[i]-'0';
    25     }
    26     a.end = strlen(str);
    27     a.begin = 0;
    28     int r=0;                    // 存储余数 
    29     bign c;
    30     for(i=0; i<a.end; ++i) {    // 相除 
    31         r = r*10+a.d[i];
    32         c.d[i] = r/b;
    33         r %= b;
    34     }
    35     c.begin = 0;
    36     c.end = a.end;
    37     // 去除前面的 0,并保证至少有一位 
    38     while(c.begin<c.end-1 && c.d[c.begin] == 0) {
    39         c.begin++;
    40     }
    41     // 输出商和余数 
    42     for(i=c.begin; i<c.end; ++i) {
    43         printf("%d", c.d[i]);
    44     }
    45     printf(" %d", r);
    46 
    47     return 0;
    48 }
  • 相关阅读:
    图像按钮
    提交按钮
    文件上传域
    Python创建虚拟环境
    Typecho使用技巧
    面向对象
    Python语法入门
    Python 基础数据类型
    与用户交互
    MySQL5.7安装教程
  • 原文地址:https://www.cnblogs.com/coderJiebao/p/PAT1017.html
Copyright © 2011-2022 走看看