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 |
测试用例全部通过 自己实在找不出问题了 希望大家可以帮忙啊~#include<stdio.h> #include<stdlib.h> #define MAX 150 int main() { char tmp_char[7]; int n, i, j, k, tag, front_tag, back_tag; int first[MAX], second[MAX], tmp[MAX], tmp_tag; while(scanf("%s%d", tmp_char ,&n) == 2) { //Initially Setting for ( i = 0; i < MAX; i++) { first[i] = second[i] = tmp[i] = 0; } //Turning into first, second tag = -1; for( i = 5, j = 0; i >= 0; i--) { if ( tmp_char[i] == '.') tag = 5 - i; else { first[j] = second[j] = tmp_char[i] - 48; j++; } } //Multiplication for ( i = 0; i < n - 1; i++) { for (j = 0; j < MAX; j++) { tmp[j] = 0; } for( j = 0; j < 6 * ( i + 1); j++) { for ( k = 0; k < 6; k++) { tmp[j + k] += first[j] * second[k]; } } for ( j = 0; j <= 6 * (i + 2); j++) { if ( tmp[j] > 9) { tmp[j + 1] += tmp[j] / 10; tmp[j] = tmp[j] % 10; } first[j] = tmp[j]; } } //(1,0) = 1 if ( n == 0) { for ( i = 0; i < MAX; i++) { first[i] = 0; } first[0] = 1; } //Transfer if ( tag != -1) tag *= n; back_tag = front_tag = -1; for ( i = 0; i < tag; i++) { if ( first[i] != 0) { back_tag = i; break; } } for ( i = MAX; i >=tag; i--) { if ( first[i] != 0) { front_tag = i; break; } } //Print if ((front_tag == -1)&&(back_tag == -1)) { printf("%d", 0); } else { if (front_tag != -1) { for ( i = front_tag; i >= (tag>=0?tag:0); i--) { printf("%d", first[i]); } } if (back_tag != -1) { printf("%c", '.'); for ( i = tag - 1; i >= back_tag; i--) { printf("%d", first[i]); } } } printf("%s", "\n"); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator