标签:des style blog color os io for ar div
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int hash[9999]; int sir[500]; char ch1[1000],ch2[1000]; int num1[100],num2[100],n1[100],n2[100],sum[100]; int main() { int k=1; for(int i=2;i<=9999;i++) { if(!hash[i]) { sir[k++]=i; for(int j=i+i;j<=9999;j+=i) hash[j]=1; } } while(scanf("%s%s",ch1,ch2)!=EOF) { if(strcmp(ch1,"0")==0&&strcmp(ch2,"0")==0) break; int k1=1,k2=1; num1[1]=num2[1]=0; for(int i=0;i<strlen(ch1);i++) { if(ch1[i]==‘,‘) { k1++; num1[k1]=0; continue; } num1[k1]=num1[k1]*10+ch1[i]-‘0‘; //cout<<num1[k1]; } //cout<<endl; for(int i=0;i<strlen(ch2);i++) { if(ch2[i]==‘,‘) { k2++; num2[k2]=0; continue; } num2[k2]=num2[k2]*10+ch2[i]-‘0‘; //cout<<num2[k2]; } //cout<<endl; memset(n1,0,sizeof(n1)); memset(n2,0,sizeof(n2)); for(int i=k1;i>0;i--) n1[k1-i+1]=num1[i]; for(int i=k2;i>0;i--) n2[k2-i+1]=num2[i]; //for(int i=1;i<=k1;i++) //printf("%d,",n1[i]); int K=k1>k2?k1:k2; for(int i=1;i<=K;i++) { if(i==1) sum[i]=n1[i]+n2[i]; else { if(sum[i-1]>=sir[i-1]) sum[i]=n1[i]+n2[i]+1; else sum[i]=n1[i]+n2[i]; } //cout<<sum[i]<<endl; } if(sum[K]>=sir[K]) sum[++K]=1; for(int i=K;i>0;i--) { if(i==K) { printf("%d",sum[i]%sir[i]); } else printf(",%d",sum[i]%sir[i]); } printf("\n"); } return 0; }
标签:des style blog color os io for ar div
原文地址:http://www.cnblogs.com/mis-xiao/p/3935178.html