标签:des style blog http color io os ar for
1 #include <iostream> 2 #include <cstdio> 3 #include <cstdlib> 4 #include <cstring> 5 #define UNIT 10 6 7 using namespace std; 8 9 struct Bignum 10 { 11 long long val[10000]; 12 int len; 13 14 Bignum () 15 { 16 memset (val, 0, sizeof(val)); 17 len = 1; 18 } 19 20 Bignum operator / (const long long &a) const//大数除小数 21 { 22 Bignum x; 23 long long down = 0; 24 for (int i = len-1; i >= 0; --i) 25 { 26 x.val[i] = (val[i]+down*UNIT) / a; 27 down = val[i] + down*UNIT - x.val[i]*a; 28 } 29 x.len = len; 30 while (x.val[x.len-1] == 0 && x.len > 1) 31 x.len--; 32 return x; 33 } 34 35 long long operator % (const long long &a) const//大数模小数 36 { 37 int x = 0; 38 for (int i = len-1; i >= 0; --i) 39 x = ((x*UNIT)%a+val[i]) % a; 40 return x; 41 } 42 43 44 }; 45 46 47 char a[10000],ch; 48 long long b; 49 int main() 50 { 51 //freopen("ACM.txt","r",stdin); 52 53 while(scanf("%s %c %lld", a, &ch, &b)!=EOF) 54 { 55 // printf("%c",ch); 56 Bignum x1,ans; 57 int La=strlen(a); 58 x1.len=0; 59 for(int i=La-1;i>=0;i--) 60 x1.val[x1.len++]=a[i]-‘0‘; 61 // cout<<ch<<b<<endl; 62 if(ch==‘/‘) 63 { 64 ans=x1/b; 65 for(int i=ans.len-1;i>=0;i--) 66 cout<<ans.val[i]; 67 cout<<endl; 68 } 69 else if(ch==‘%‘) 70 { 71 cout<<x1%b<<endl; 72 } 73 } 74 return 0; 75 }
标签:des style blog http color io os ar for
原文地址:http://www.cnblogs.com/M-D-LUFFI/p/4050178.html