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 <iostream> #include <cstring> using namespace std; #define NUMSIZE 200 class BIGNUM { public: int length; int ndot; int value[NUMSIZE]; BIGNUM() { length = 0; ndot = 0; memset(value, 0, sizeof(value)); } BIGNUM(char *str) { length = 0; ndot = 0; memset(value, 0, sizeof(value)); int j = 0; for(int i = strlen(str) - 1; i >= 0; i--) { if(str[i] == '.') { ndot = j; } else { value[j++] = str[i] - '0'; length++; } } for(int i = length - 1; i >= 0 && 0 == value[i]; i--, length--); } friend BIGNUM operator *(BIGNUM a, BIGNUM b) { BIGNUM result; for(int i = 0; i < a.length; i++) for(int j = 0; j < b.length; j++) result.value[i + j] += a.value[i] * b.value[j]; for(int i = 0; i < a.length + b.length; i++) { if(result.value[i] >= 10) { result.value[i + 1] += result.value[i] / 10; result.value[i] %= 10; } } int k; for(k = a.length + b.length - 1; k >= 0 && 0 == result.value[k]; k--); result.length = k + 1; result.ndot = a.ndot + b.ndot; return result; } friend ostream & operator <<(ostream &os, BIGNUM &num) { if(0 == num.length) os << "0"; // 输出整数 else if(0 == num.ndot) for(int i = num.length - 1; i >= 0; i--) os << num.value[i]; // 位不够补0 else if(num.ndot > num.length) { os << "."; // 忽略最后面的0 int overlook = 0; for(; overlook < num.ndot && 0 == num.value[overlook]; overlook++); for(int i = num.ndot - 1; i >= overlook; i--) os << num.value[i]; } else { // 忽略最后面的0 int overlook = 0; for(; overlook < num.ndot && 0 == num.value[overlook]; overlook++); for(int i = num.length - 1; i >= overlook; i--) { if(i + 1 == num.ndot) os << "."; os << num.value[i]; } } return os; } }; int main() { char num[NUMSIZE]; int p; while(cin >> num >> p) { if(0 == p) { cout << "1\n"; continue; } BIGNUM a; a.length = 1; a.value[0] = 1; BIGNUM b(num); while(p--) a = a * b; cout << a << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator