zoukankan      html  css  js  c++  java
  • POJ Problem 2562 Primary Arithmetic

    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 11358   Accepted: 4172

    Description

    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.
    

    Source

    Waterloo local 2000.09.23

    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    #include <queue>
    #include <stack>
    #include <iostream>
    #define MAX_N   106
    #define MAX(a, b) (a > b)? a: b
    #define MIN(a, b) (a < b)? a: b
    using namespace std;
    
    int main() {
        int a, b;
        int s1[MAX_N], s2[MAX_N];
        while (scanf("%d%d", &a, &b) ,a || b) {
            for (int i = 0; i < 20; i++) {
                s1[i] = s2[i] = 0;
            }
            int ans = 0;
            int cnt = 0;
            while (a) {
                s1[cnt++] = a%10;
                a /= 10;
            }
            cnt = 0;
            while (b) {
                s2[cnt++] = b%10;
                b /= 10;
            }
            for (int i = 0; i < 11; i++) {
                s1[i] += s2[i];
                if (s1[i] > 9) {
                    ans++;
                    s1[i + 1]++;
                }
            }
            if (!ans) printf("No carry operation.
    ", ans);
            else if (ans == 1) printf("%d carry operation.
    ", ans);
            else printf("%d carry operations.
    ", ans);
    
        }
        return 0;
    }
    


  • 相关阅读:
    vsftpd 启动 vsftpd:500 OOPS: bad bool value in config file for: guest_enable
    Vsftpd服务传输文件(转)
    搭建FTP服务
    sed命令
    创建服务类脚本
    jvm 方法区
    B+与B-树
    适配器模式
    java 垃圾回收总结(可达性分析 引用分类
    HBase常见问题答疑解惑【持续更新中】
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770938.html
Copyright © 2011-2022 走看看