今天新写的高精度板子!神清气爽
struct HAI { static const int Mx = 105; int num[Mx],len; HAI() { clean(); } void clean() { memset(num,0,sizeof(num)); len = 1; } void read() { char str[Mx]; scanf("%s",str); len = strlen(str); for(int i = 1; i <= len; i++) num[i] = str[len-i] - '0'; } void write() { for(int i = len; i >= 1; i--) printf("%d",num[i]); } void ItoHAI(int x) { clean(); while(x) { num[len++] = x % 10; x /= 10; } if(len != 1) len--; } HAI operator + (const HAI &A) const { HAI S; S.len = max(len,A.len); for(int i = 1; i <= S.len; i++) { S.num[i] += num[i] + A.num[i]; if(S.num[i] >= 10) { S.num[i] -= 10; S.num[i+1]++; } } while(S.num[S.len+1]) S.len++; return S; } HAI operator - (const HAI &A) const { HAI S; S.len = max(len,A.len); for(int i = 1; i <= S.len; i++) { S.num[i] += num[i] - A.num[i]; if(S.num[i] < 0) { S.num[i] += 10; S.num[i+1]--; } } while(!S.num[S.len] && S.len > 1) S.len--; return S; } HAI operator * (const HAI &A) const { HAI S; S.len = len + A.len - 1; for(int i = 1; i <= len; i++) for(int j = 1; j <= A.len; j++) { int k = i+j-1; S.num[k] += num[i] * A.num[j]; S.num[k+1] += S.num[k] / 10; S.num[k] %= 10; } while(S.num[S.len+1]) S.len++; while(!S.num[S.len] && S.len > 1) S.len--; return S; } bool operator < (const HAI &A) const { if(len != A.len) return len < A.len; for(int i = len; i >= 1; i--) if(num[i] != A.num[i]) return num[i] < A.num[i]; return false; } bool operator > (const HAI &A) const { return A < *this; } bool operator == (const HAI &A) const { return !(*this < A || A < *this); } };