1058 A+B in Hogwarts (20分)

五迷三道 提交于 2020-03-05 23:54:49

1. 题目

2. 思路

常规题

3. 注意点

4. 代码

#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<string>

using namespace std;

struct num{
    int n1;
    int n2;
    int n3;
    num(){
    }
    num(int n1, int n2, int n3){
        this->n1 = n1;
        this->n2 = n2;
        this->n3 = n3;
    }
};

num add(num a, num b){
    num c;
    int flag1 = 0, flag2 = 0;
    if(a.n3 + b.n3 >= 29){
        flag1 = 1;
    }
    c.n3 = (a.n3 + b.n3) % 29;
    if(a.n2 + b.n2 + flag1 < 17){
        flag2 = 0;
    }else{
        flag2 = 1;
    }
    c.n2 = (a.n2 + b.n2 + flag1) % 17;
    c.n1 = a.n1 + b.n1 + flag2;
    return c;
}

int n1, n2, n3;
int main(){
    scanf("%d.%d.%d", &n1, &n2, &n3);
    num a(n1, n2, n3);
    scanf("%d.%d.%d", &n1, &n2, &n3);
    num b(n1, n2, n3);
    num c = add(a, b);
    printf("%d.%d.%d", c.n1, c.n2, c.n3);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!