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 |
尝试了前辈的变态数据,都过了,可是还是wrong answer啊?请大家看下#include <stdio.h> #include <string.h> #include <stdlib.h> typedef struct { char bit[160]; // 存储每一位的数值 int len; // 数据长度 int index; // 小数点位置 } big_float; #define INDEX_INIT 200 // 初始化小数点位置 //int INDEX_INT = 200; void make_small(big_float *f) { int start = 0,i,j,len; // 去首零 while((f->bit[start] == 0) && (start <= f->len-1)) start ++; if(start <= (f->len-1)) len = f->len - start; else { f->len = 0; return; } j = start; for(i = 0; i < len; i ++) { f->bit[i] = f->bit[j++]; } f->len -= start; if(f->index != INDEX_INIT) f->index -= start; // 去尾零 len = f->len; start = f->len - 1; while((start >= 0) && (f->bit[start] == 0) && (f->index != INDEX_INIT)) start --; if((start >= 0) && (f->index != INDEX_INIT) && (start+1 < f->len)) { f->len = start + 1; } else if((f->index == INDEX_INIT) ) f->index = len; } void GetR(char *s,big_float *f) { int i = 0,j = 0; memset(f,0,sizeof(big_float)); f->index = INDEX_INIT; while(s[i]) // 6位数字 { if(s[i] != '.') f->bit[j++] = s[i] - '0'; else f->index = i; i ++; } f->len = j; make_small(f); } void print_float(big_float *f) { int i,j; j = f->index; if(j < 0) putchar('.'); while(j < 0) { putchar('0'); j ++; } for(i=0; i < f->len; i ++) { if(f->index != i) printf("%c",f->bit[i]+'0'); else { printf(".%c",f->bit[i]+'0'); } } j = f->len; while((j < f->index) && (f->index != INDEX_INIT)) { putchar('0'); j ++; } } void print_float2(big_float *f) { int i,j; char temp[100] = {0}; int k = 0; j = f->index; if(j < 0) { temp[k ++] = '.'; } while(j < 0) { temp[k ++] = '0'; j ++; } for(i=0; i < f->len; i ++) { if(f->index == i) { temp[k ++] = '.'; } temp[k ++] = f->bit[i] + '0'; } j = f->len; while((j < f->index) && (f->index != INDEX_INIT)) { temp[k ++] = f->bit[i] + '0'; j ++; } puts(temp); } // 低低高高 到 高低高低 void converse_float(big_float *t,big_float *f) { int i,j = 0; memset(f,0,sizeof(big_float)); f->index = t->index; f->len = t->len; for(i = t->len-1; i >= 0; i --) { f->bit[j++] = t->bit[i]; } } // f = f * l void multi_float(big_float *f,big_float *l) { big_float t; int i,j,k = 0; int cf = 0; // 进位标志 int rt = 0; int len = 0; memset(&t, 0, sizeof(big_float)); t.index = INDEX_INIT; for(i = l->len-1; i >= 0; i --) { for(j = f->len-1; j >= 0; j --) { rt = (f->bit[j]) * (l->bit[i]) + cf; cf = rt / 10; t.bit[k] += rt % 10; // t为低低高高存储 if(t.bit[k] > 9) { t.bit[k+1] += 1; t.bit[k] -= 10; } k ++; } if(cf) // 处理cf进位 { t.bit[k ++] += cf; } len = k; k = l->len - i; cf = 0; } j = 0; t.len = len; if(f->len != INDEX_INIT) t.index = t.len - (f->len - f->index + l->len - l->index); else t.index = INDEX_INIT; converse_float(&t,f); make_small(f); } // f ^ n void pow_float(big_float *f,int n) { int i; big_float l; make_small(f); memset(&l,0,sizeof(big_float)); for(i = 0; i < f->len; i ++) l.bit[i] = f->bit[i]; l.len = f->len; l.index = f->index; for(i = 0; i < n-1; i ++) { multi_float(f,&l); } } void Solve(char *s,int n) { big_float r; GetR(s, &r); if(n == 0) printf("1\n"); else if(r.len != 0) { pow_float(&r,n); print_float2(&r); } else printf("0\n"); //printf("\n"); } int main() { char s[7]; int n; while(scanf("%s%d",s,&n)==2) { Solve(s, n); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator