标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 11713 Accepted Submission(s):
3924
一开始想化成十进制的求每位权值,做了半天结果发现这样不行
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 #define LL long long 7 int prime[100]; 8 int flag=0; 9 void GetPrime() 10 { 11 int i,j=0,k; 12 for(i=2;;i++) 13 { 14 flag=0; 15 for(k=2;k<=sqrt(i);k++) 16 { 17 if(i%k==0) 18 { 19 flag=1; 20 break; 21 } 22 } 23 if(!flag) 24 prime[j++]=i; 25 if(j==30) 26 break; 27 } 28 return; 29 } 30 int main() 31 { 32 char a[100],b[100]; 33 GetPrime(); 34 //freopen("in.txt","r",stdin); 35 while(scanf("%s %s",a,b)) 36 { 37 if(a[0]==‘0‘&&b[0]==‘0‘) 38 break; 39 else 40 { 41 int A[100],B[100],C[100]; 42 memset(A,0,sizeof(A)); 43 memset(B,0,sizeof(B)); 44 memset(C,0,sizeof(C)); 45 int suma=0,sumb=0,k=1,j=0,i=0,sum; 46 int lena=strlen(a),lenb=strlen(b); 47 for(i=lena-1;i>=0;i--) 48 { 49 k=0; 50 while(a[i]!=‘,‘) 51 { 52 A[j]+=(a[i]-‘0‘)*pow(10,k); 53 k++; 54 i--; 55 if(i<0) 56 break; 57 } 58 j++; 59 } 60 int ga=j; 61 j=0; 62 for(i=lenb-1;i>=0;i--) 63 { 64 k=0; 65 while(b[i]!=‘,‘) 66 { 67 B[j]+=(b[i]-‘0‘)*pow(10,k); 68 k++; 69 i--; 70 if(i<0) 71 break; 72 } 73 j++; 74 } 75 int gb=j; 76 int c=0; 77 for(i=0;i<=25;i++) 78 { 79 C[i]=(A[i]+B[i]+c)%prime[i]; 80 c=(A[i]+B[i]+c)/prime[i]; 81 } 82 for(i=99;i>=0;i--) 83 if(C[i]!=0) 84 break; 85 int count=i; 86 for(;i>0;i--) 87 cout<<C[i]<<‘,‘; 88 cout<<C[i]; 89 cout<<endl; 90 } 91 } 92 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/4883901.html