zoukankan      html  css  js  c++  java
  • [解题报告]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;
    
    
    
    }

  • 相关阅读:
    思科模拟器——常用命令
    思科模拟器——允许远程telnet连接控制路由器/交换机
    思科模拟器——使用路由器分割局域网
    如何将centos7作为DNS服务器
    Centos7设置grub密码保护
    curl提示不支持https协议解决方法
    Kettle入门--作业和转换的使用
    oracle命令导入SQL脚本
    centos7 部署elasticsearch
    Nginx通过Keepalived实现高可用
  • 原文地址:https://www.cnblogs.com/TheLaughingMan/p/2908279.html
Copyright © 2011-2022 走看看