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;
    }
    


  • 相关阅读:
    Oracle中的rownum
    关于Oracle12c中无scott用户的问题
    docker 1.13 是什么版本?
    ImportError: cannot import name 'SQLALchemy'
    mac配置iterm2,iterm2使用方法
    docker 时区
    jupyter 500 : Internal Server Error
    sublime conda 切换环境
    mac frida安装(使用网易木木模拟器)
    \u开头两个字符的是什么编码?
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770938.html
Copyright © 2011-2022 走看看