UVA - 10494 If We Were a Child Again

来源:互联网 发布:淘宝网开店费用 编辑:程序博客网 时间:2024/06/05 18:13

题目大意:高精度除法

解题思路:循环记录余数和商,输出所求。余数在做被除数时需要 ×10 所以可能会大于 2^31,用 long long

#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<ctype.h>using namespace std;char t[10000];int ans[10000], a[10000];char sign;long long b;int main() {    while (scanf("%s %c %lld", t, &sign, &b) != EOF) {        int len = strlen(t);        for (int i = 0; i < len; i++)            a[i] = t[i] - '0';        long long tmp = 0;        int t = 0;        int tag = 0;        while (t < len) {            tag++;            tmp = tmp * 10 + a[t];            ans[tag] = tmp / b;            tmp %= b;            t++;        }        if (sign == '%') printf("%lld\n", tmp);        else {            int i = 0;            while (ans[i] == 0 && i < len) i++;            while (i <= len) printf("%d",ans[i++]);            printf("\n");        }    }    return 0;}
0 0
原创粉丝点击