Hdu1230 mars A + B (Big Data)

Source: Internet
Author: User
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 input1, 0, 01, 6, 10 0

 

Sample output1, use a big number method to separate one digit for the final reverse output
#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;}

 

Hdu1230 mars A + B (Big Data)

Related Article

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.