Source: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1230
Mars A + B
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 10562 accepted submission (s): 3524
Problem description reads two positive integers A and B of Mars, and calculates a + B. It should be noted that on Mars, integers are not in single hexadecimal notation, And the nth hexadecimal notation is the nth prime number. For example, the 10 hexadecimal number 2 on the earth is counted as "1, 0" on Mars, because the single digit of Mars is 2 hexadecimal; the 10 hexadecimal number on the earth is 38, on Mars, it is recorded as ",", because the number of single digits of Mars is in hexadecimal notation, the number of digits is in hexadecimal notation, and the number of digits is in hexadecimal notation, the number of thousands is in the 7-digit format ......
Input test input contains several test cases. Each test case occupies one row and contains two positive integers A and B. The two adjacent double digits of the positive integers are separated by commas (,), and there is a space interval between A and B. When expression a or expression B is 0, the input ends, and the corresponding results are not output.
Output outputs one line for each test case, that is, the value of A + B in the Mars notation.
Sample Input
1,0 2,14,2,0 1,2,01 10,6,4,2,10 0
Sample output
1,0,11,1,1,01,0,0,0,0,0
Source Zhejiang University Computer postgraduate review computer examination-2006
Question: omitted
Problem: large numbers. An array of ANS is used to store the numbers in hexadecimal notation. The two arrays N1 N2 respectively store the numbers of two Mars. In terms of programming implementation, it is mainly because the input at the beginning requires some skills.
AC code:
#include<iostream>#include<cstring>#include<cmath>#include<cstdio>using namespace std;bool prime(int k){if(k==2||k==3)return true;for(int i=2;i<=(int)sqrt(float(k));i++)if(k%i==0) return false;return true; }const int Max=55;int num1[Max],num2[Max],N1[Max],N2[Max],posx=0,posy=0,temp; int ans[60+5];char ch;int main(){int tpos=0;for(int i=2;tpos<56;i++)if(prime(i)) ans[tpos++]=i;while(1){posx=0,posy=0;memset(N1,0,sizeof(N1)); memset(N2,0,sizeof(N2));while(1){scanf("%d",&temp);ch=getchar();num1[posx++]=temp;if(ch==' ')break;}while(1){scanf("%d",&temp);ch=getchar();num2[posy++]=temp;if(ch=='\n')break;}//posx++; posy++;if((posx==1&&!num1[0])||(posy==1&&!num2[0]))return 0; for(int i=posx-1;i>=0;i--) N1[posx-i-1]=num1[i]; for(int i=posy-1;i>=0;i--) N2[posy-i-1]=num2[i]; for(int i=0;i<Max-2;i++){ N1[i]+=N2[i]; if(N1[i]>=ans[i]){ N1[i+1]++;N1[i]%=ans[i]; } } int k; for(k=Max-3;k>0&&!N1[k];)k--; for(;k>0;k--) printf("%d,",N1[k]); printf("%d\n",N1[0]);}}