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 |
10.000 1无语了#include <iostream> #include <string> const int HUGEINTEGERSIZE = 1000; using namespace std; inline int getSize(int a[]) { int i = 0; while (i < HUGEINTEGERSIZE && a[i++] == 0) { } return HUGEINTEGERSIZE + 1 - i; } int main() { string input; while (cin>>input) { int number[HUGEINTEGERSIZE] = { 0 }; int a[HUGEINTEGERSIZE] = { 0 }; int dotpos=0,status=false; for(int i=input.length()-1,ai = 1;i>=0;--i) { if (input[i] == '.') { status = true; } else { if (status == false) ++dotpos; a[HUGEINTEGERSIZE - ai] = input[i] - '0'; ai++; } } if (status==false) dotpos = 0; else { int zero = 0,i=HUGEINTEGERSIZE - 1; while (a[i] == 0&&zero<dotpos) { --i; ++zero; } if (zero > 0) { for (; i >= 0; --i) a[i + zero] = a[i]; dotpos -= zero; } } int n; cin >> n; if (n > 0) { int decnum = dotpos * n; int tempNum[HUGEINTEGERSIZE] = { 0 }; tempNum[HUGEINTEGERSIZE - 1] = 1; int i, j; while (n-- > 0) { for (int i = 0; i < HUGEINTEGERSIZE; i++) { number[i] = 0; } int M = getSize(a), N = getSize(tempNum); for (i = 0; i < N; ++i) { for (j = 0; j < M; ++j) { number[HUGEINTEGERSIZE - 1 - j - i] += tempNum[HUGEINTEGERSIZE - 1 - i] * a[HUGEINTEGERSIZE - 1 - j]; } } for (i = HUGEINTEGERSIZE - 1; i >= HUGEINTEGERSIZE - M - N && i > 0; --i) { if (number[i] >= 1000) { number[i - 3] += number[i] / 1000; number[i] %= 1000; } if (number[i] >= 100) { number[i - 2] += number[i] / 100; number[i] = number[i] % 100; } if (number[i] >= 10) { number[i - 1] = number[i] / 10 + number[i - 1]; number[i] = number[i] % 10; } } for (int i = 0; i < HUGEINTEGERSIZE; ++i) tempNum[i] = number[i]; } if (decnum >= getSize(number)) { cout << '.'; for (int i = HUGEINTEGERSIZE - decnum; i < HUGEINTEGERSIZE; ++i) { cout << number[i]; } } else if (decnum > 0) { i = 0; while (i < HUGEINTEGERSIZE && number[i] == 0) { i++; } for (; i < HUGEINTEGERSIZE - decnum; ++i) cout << number[i]; cout << '.'; for (; i < HUGEINTEGERSIZE; ++i) cout << number[i]; } else { i = 0; while (i < HUGEINTEGERSIZE && number[i] == 0) { i++; } if (i >= HUGEINTEGERSIZE) { cout << 0; } for (; i < HUGEINTEGERSIZE; ++i) cout << number[i]; } } else { cout << 1; } cout << endl; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator