标签:amp include tor ace ons play code break name
网上的鱼龙混杂,不如自己写个。
1 char str[1000]; 2 int a[1000],b[1000],c[1000]; 3 4 int main(){ 5 scanf("%s",str); 6 int len = strlen(str); 7 for(int i = len-1;i >= 0;i--)a[len-i] = str[i]-‘0‘; 8 scanf("%s",str); 9 int n = len; 10 len = strlen(str); 11 for(int i = len-1;i >= 0;i--)b[len-i] = str[i]-‘0‘; 12 int m = len; 13 n = max(n,m); 14 15 for(int i = 1;i <= n;i++)c[i] = a[i]+b[i]; 16 for(int i = 1;i <= n;i++)c[i+1] += c[i]/10,c[i] %= 10; 17 while(c[n] > 10||c[n+1])c[n+1] += c[n]/10,c[n] %= 10,n++; 18 19 for(int i = n;i > 0;i--)putchar(c[i]+‘0‘);putchar(‘\n‘); 20 21 return 0; 22 }
1 char s[1000]; 2 int b; 3 int a[1000],c[1000]; 4 int n,m; 5 6 int main(){ 7 scanf("%s",s); 8 int n = strlen(s); 9 for(int i = n-1;i >= 0;i--)a[n-i] = s[i] - ‘0‘; 10 scanf("%d",&b); 11 12 for(int i = 1;i <= n;i++)c[i] = a[i]*b; 13 for(int i = 1;i <= n;i++)c[i+1] += c[i]/10,c[i] %= 10; 14 while(c[n] > 10||c[n+1])c[n+1] += c[n]/10,c[n] %= 10,n++; 15 16 for(int i = n;i >= 1;i--)putchar(c[i]+‘0‘); 17 18 return 0; 19 }
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #include<cstdlib> 6 #include<algorithm> 7 using namespace std; 8 9 struct bignum{ 10 int a[1000]; 11 int len; 12 13 void init(){memset(a,0,sizeof(a));} 14 15 void get(){ 16 init(); 17 char s[1000]; 18 scanf("%s",s); 19 len = strlen(s); 20 for(int i = len-1;i >= 0;i--)a[len-i] = s[i]-‘0‘; 21 } 22 23 void print(){ 24 for(int i = len;i > 0;i--)putchar(a[i]+‘0‘); 25 } 26 27 void initlen(){ 28 for(len = 999;len > 0;len--)if(a[len])break; 29 } 30 31 bignum operator *(const bignum& x){ 32 bignum ans; 33 ans.init(); 34 for(int i = 1;i <= len;i++) 35 for(int j = 1;j <= x.len;j++) 36 ans.a[i+j-1] += a[i]*x.a[j]; 37 for(int i = 1;i < 1000;i++)ans.a[i+1] += ans.a[i]/10,ans.a[i] %= 10; 38 ans.initlen(); 39 return ans; 40 } 41 42 }x,y,z; 43 44 bignum div(bignum x,int y){ 45 bignum ans; 46 ans.init(); 47 int now = 0,cur = x.len+1; 48 while(now < y){ 49 cur--; 50 now = now*10+x.a[cur]; 51 } 52 ans.len = cur; 53 while(cur){ 54 ans.a[cur] = now/y; cur--; 55 now = now%y*10+x.a[cur]; 56 } 57 return ans; 58 } 59 60 int w; 61 62 int main(){ 63 x.get(); cin >> w; 64 div(x,w).print(); 65 return 0; 66 }
标签:amp include tor ace ons play code break name
原文地址:https://www.cnblogs.com/Wangsheng5/p/11627237.html