Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
过了,不过有一个莫名其妙的presentation error#include <stdio.h> #include <stdlib.h> //#include <iostream> //#include <iomanip> //#include <cstdio> //using namespace std; #define MAX (63) #define BASE (100000) #define LGBASE (5) typedef long long INT; typedef struct { INT digit[MAX]; int len; } bigint; void output(bigint *a, int expo) { int i, j; char str[256]; // memset(str, 0, sizeof(str)); for(i = a->len - 1; i >= 0; i--) { sprintf(str + (a->len - 1 - i) * LGBASE, "%5lld", a->digit[i]); for(j = (a->len - 1 - i) * LGBASE; str[j] == ' '; j++) { str[j] = '0'; } } expo += LGBASE * a->len; if(expo < 0) { j = a->len * LGBASE; while(str[j - 1] == '0') { j--; } str[j] = '\0'; putchar('.'); while(expo < 0) { putchar('0'); expo++; } // puts(str); 假如用这行输出后会有一个莫名其妙的换行,别的地方都不会这样 for(j = 0; str[j] != '\0'; j++) { putchar(str[j]); } } else { if(expo >= LGBASE * a->len) { for(i = 0; str[i] == '0'; i++) { ; } puts(str + i); for(j = 0; j < expo - LGBASE * a->len; j++) { putchar('0'); } } else { j = a->len * LGBASE; while(str[j - 1] == '0') { j--; } str[j] = '\0'; for(i = 0; str[i] == '0' && i < expo; i++) { ; } for(j = i; str[j] != '\0'; j++) { if(j == expo) { putchar('.'); } putchar(str[j]); } while(j < expo) { putchar('0'); j++; } } } putchar('\n'); } bigint mult(bigint *a, bigint *b) { int i, j; INT carry = 0; bigint p; p.len = a->len + b->len; for(i = 0; i < p.len; i++) { p.digit[i] = 0; } for(i = 0; i < a->len; i++) { for(j = 0; j < b->len; j++) { p.digit[i + j] += a->digit[i] * b->digit[j]; } } for(i = 0; i < p.len; i++) { p.digit[i] += carry; carry = p.digit[i] / BASE; p.digit[i] %= BASE; } if(p.digit[p.len - 1] == 0) { p.len--; } return p; } int main(int argc, char** argv) { char str[8]; int n; while(scanf("%6s %2d\n", str, &n) != EOF) // while(cin >> str, cin >> n, /*cin >> pad,*/ !cin.fail()) { int expo; bigint base, power; power.len = 1; power.digit[0] = 1; base.len = 1; if(str[0] == '.') { expo = -5 * n; base.digit[0] = (str[1] - '0') * 10000 + (str[2] - '0') * 1000 + (str[3] - '0') * 100 + (str[4] - '0') * 10 + (str[5] - '0'); } if(str[1] == '.') { expo = -4 * n; base.digit[0] = (str[0] - '0') * 10000 + (str[2] - '0') * 1000 + (str[3] - '0') * 100 + (str[4] - '0') * 10 + (str[5] - '0'); } if(str[2] == '.') { expo = -3 * n; base.digit[0] = (str[0] - '0') * 10000 + (str[1] - '0') * 1000 + (str[3] - '0') * 100 + (str[4] - '0') * 10 + (str[5] - '0'); } if(str[3] == '.') { expo = -2 * n; base.digit[0] = (str[0] - '0') * 10000 + (str[1] - '0') * 1000 + (str[2] - '0') * 100 + (str[4] - '0') * 10 + (str[5] - '0'); } if(str[4] == '.') { expo = -n; base.digit[0] = (str[0] - '0') * 10000 + (str[1] - '0') * 1000 + (str[2] - '0') * 100 + (str[3] - '0') * 10 + (str[5] - '0'); } if(str[5] == '.') { expo = 0; base.digit[0] = (str[0] - '0') * 10000 + (str[1] - '0') * 1000 + (str[2] - '0') * 100 + (str[3] - '0') * 10 + (str[4] - '0'); } while(n > 0) { if(n % 2 == 1) { power = mult(&power, &base); } base = mult(&base, &base); n >>= 1; } output(&power, expo); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator