Mars a+b

Source: Internet
Author: User

Description

Read two non-25-bit Mars positive integers a and B, calculate a+b. It is important to note that on Mars, integers are not single-binary, and nth-bit is the nth prime. For example: 10 binary number 2 on Earth, on Mars as "1,0", because the number of Mars single-digit is 2 binary, the Earth's 10 number of 38, on Mars as "1,1,1,0", because the Mars single-digit is 2 binary, 10-digit is 3, the Hundred is 5 binary, thousand is 7 binary ...

Input

The test input contains several test cases, one row for each test case, two Martian positive integers a and B, a comma-separated number of adjacent two-digit numbers for the Mars Integer, and a space interval between a and B. When a or B is 0 o'clock input end, the corresponding result does not output.

Output

Output 1 lines for each test case, that is, the a+b value of the Mars notation.

Sample Input

1,0 2,1 4,2,0 1,2,0 1 10,6,4,2,1 0 0

Sample Output

1,0,1 1,1,1,0 1,0,0,0,0,0 Personal Feelings This problem has been tested many times, forgetting the equal sign and the character array is too small to waste time sourcehttp://acm.hust.edu.cn/vjudge/contest/ View.action?cid=89340#problem/d
#include <stdio.h>#include<math.h>#include<string.h>intPrimeintx) {    intFlag =1;  for(inti =2; I <= sqrt (x); i++)    {        if(x% i = =0) {flag=0;  Break; }    }    returnFlag;}intMain () {intp[ -], top =0, Len1, Len2, num1[ -], num2[ -], ans[ -]; Charstr1[ +], str2[ +];  for(inti =2; Top < -; i++)    {        if(Prime (i)) {P[top++] =i; //printf ("%d\n\n", P[top-1]);        }    }     while(~SCANF ("%s%s", STR1, str2)) {        if(strcmp (STR1,"0") ==0|| strcmp (STR2,"0") ==0)             Break; memset (NUM1,0,sizeof(NUM1)); memset (num2,0,sizeof(num2)); memset (ans,0,sizeof(ans)); Top=0; intK =1, CNT; Len1=strlen (STR1); Len2=strlen (STR2); /*for (int i = 0; i < len1; i++) {printf ("%c:%c\n", Str1[i], str2[i]); } printf ("\ n"); */        //printf ("len1 =%d Len2 =%d\n", len1, len2);         for(inti = len1-1; I >=0; i--)        {            if(Str1[i] = =',') {Top++; K=1; Continue; } Num1[top]+ = (Str1[i]-'0') *K; //printf ("i =%d:num1[%d] =%d\n\n", I, Top, num1[top]);K = k*Ten; } CNT= top+1; //printf ("cnt =%d\n", cnt);top =0; K=1;  for(inti = len2-1; I >=0; i--)        {            if(Str2[i] = =',') {Top++; K=1; Continue; } Num2[top]+ = (Str2[i]-'0') *K; //printf ("i =%d:num2[top] =%d\n\n", I, Top, num2[top]);K = k*Ten; }        if(top+1>CNT) CNT= top+1; //printf ("cnt =%d\n", cnt);         for(inti =0; I < CNT; i++) {Ans[i]+ = Num1[i] +Num2[i];  while(Ans[i] >= p[i] && p[i]! =0) {ans[i+1] + = Ans[i]/P[i]; Ans[i]%=P[i]; }            //printf ("ans[%d] =%d, num1[%d] =%d, num2[%d] =%d\n", I, ans[i], I, num1[i], I, num2[i]);K = i+1; }        if(Ans[k]) printf ("%d,", Ans[k]);  for(inti = cnt-1; i >0; i--) printf ("%d,", Ans[i]); printf ("%d\n", ans[0]); }}

Mars a+b

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.