PAT 1058 A+B in Hogwarts

#include <cstdio>
#include <cstdlib>

using namespace std;

class Number {
public:
    int a;
    int b;
    int c;
    Number(int _a = 0, int _b = 0, int _c = 0): a(_a), b(_b), c(_c){}
    Number operator+(const Number& n) {
        Number tmp;
        tmp.a = a + n.a;
        tmp.b = tmp.a / 29;
        tmp.a = tmp.a % 29;
        
        tmp.b += b + n.b;
        tmp.c = tmp.b / 17;
        tmp.b = tmp.b % 17;
        
        tmp.c += c + n.c;
        tmp.c = tmp.c;
        return tmp;
    }
    void print() {
        printf("%d.%d.%d", c, b, a);
    }
};

int main() {
    Number n1, n2;
    scanf("%d.%d.%d", &n1.c, &n1.b, &n1.a);
    scanf("%d.%d.%d", &n2.c, &n2.b, &n2.a);

    Number n3 = n1 + n2;
    n3.print();
    return 0;
}

感觉是个坑,明明说了Galleon is an integer in [0, 107],结果tmp.c不用取模就对了,麻烦把定义说明白一些

posted @ 2014-11-04 00:09  卖程序的小歪  阅读(473)  评论(0编辑  收藏  举报