• [解题报告]10035 Primary Arithmetic


    Problem B: Primary Arithmetic

    Children are taught to add multi-digit numbers from right-to-left one digit at a time. Many find the "carry" operation - in which a 1 is carried from one digit position to be added to the next - to be a significant challenge. Your job is to count the number of carry operations for each of a set of addition problems so that educators may assess their difficulty.

    Input

    Each line of input contains two unsigned integers less than 10 digits. The last line of input contains 0 0.

    Output

    For each line of input except the last you should compute and print the number of carry operations that would result from adding the two numbers, in the format shown below.

    Sample Input

    123 456
    555 555
    123 594
    0 0
    

    Sample Output

    No carry operation.
    3 carry operations.
    1 carry operation.


    带中文注释提交居然会编译错误= =
    依旧是按字符组处理大数

    #include<stdio.h>
    int main()
    {
        int i,j,c,count,temp;
        char a[11],b[11];
        while(scanf("%s%s",a,b)&&(a[0]!='0'||b[0]!='0'))   //将输入的数当做字符型存贮起来,有利于处理大数和数位运算
        {
            count=0;
            c=0;
            for(i=0;a[i];i++);
            for(j=0;b[j];j++);
            i--;                //i为第一个数的位数或是有0的位数,0优先
            j--;                //j为第二个数的位数或是有0的位数,0优先
            while(j>=0&&i>=0)
            {
                temp=(a[i]-'0')+(b[j]-'0')+c;
                c=temp/10;
                if(c>0)
                    count++;
    
                i--;
                j--;
            }
            while(i>=0)
            {
                temp=a[i--]-'0'+c;
                c=temp/10;
                if(c>0)
                    count++;
            }
            while(j>=0)
            {
                temp=b[j--]-'0'+c;
                c=temp/10;
                if(c>0)
                    count++;
            }
            if(count==0)
                printf("No carry operation.\n");
            else
                if(count>=2)
                    printf("%d carry operations.\n",count);
                else
                    printf("%d carry operation.\n",count);
        }
    
        return 0;
    
    
    
    }

  • 相关阅读:
    Serveral effective linux commands
    Amber learning note A8: Loop Dynamics of the HIV-1 Integrase Core Domain
    amber初学……
    anaconda使用
    python中的一些语法
    python中的OOP
    python中的模块
    将python程序打包成exe
    python-执行过程
    python基础
  • 原文地址:https://www.cnblogs.com/TheLaughingMan/p/2908279.html
Copyright © 2020-2023  润新知