⬆︎
×

[PAT-A] 1058 A+B in Hogwarts

Hyplus目录

Java

import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] parts = br.readLine().split(" ");
        String[] first = parts[0].split("\\.");
        String[] second = parts[1].split("\\.");

        int a = Integer.parseInt(first[0]);
        int b = Integer.parseInt(first[1]);
        int c = Integer.parseInt(first[2]);
        int d = Integer.parseInt(second[0]);
        int e = Integer.parseInt(second[1]);
        int f = Integer.parseInt(second[2]);

        a += d;
        b += e;
        c += f;

        b += c / 29;
        c %= 29;

        a += b / 17;
        b %= 17;

        System.out.printf("%d.%d.%d\n", a, b, c);
    }
}

C++

#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int a, b, c, d, e, f;

int main() {
    scanf("%d.%d.%d %d.%d.%d", &a, &b, &c, &d, &e, &f);
    a += d;
    b += e;
    c += f;

    b += c / 29;
    c %= 29;

    a += b / 17;
    b %= 17;

    printf("%d.%d.%d\n", a, b, c);

    return 0;
}

发表评论