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


  • 相关阅读:
    python获取股票数据接口
    Excel使用VBA读取实时WebService股票数据
    安装Pycharm
    Pycharm2019使用
    KLine
    pycharm下用mysql
    新浪股票接口
    SpringBoot整合持久层技术--(二)MyBatis
    SpringBoot整合持久层技术--(一)JdbcTemplate
    SpringBoot整合WEB开发--(十)配置AOP
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770938.html
Copyright © 2011-2022 走看看