题解 | 三角形相加

三角形相加

https://www.nowcoder.com/practice/cb867ebc313f480cbbf0a1b334d3a1fc

我这输入输出真的没毛病吗

#include <cstdio>

class triangle {
private:
    int y, x; // 分别代表A和B的纵坐标和横坐标
public:
    triangle(int y = 0, int x = 0) : y(y), x(x) {}
    int display_x() {
        return x;
    }
    int display_y() {
        return y;
    }
    triangle operator+(const triangle &other) {
        return triangle(y + other.y, x + other.x);
    }
};

int main() {
    int a, b;
    triangle ans;
    while (scanf("%d%d", &a, &b) != EOF) {
        if (!a) break;   // 某条边长度是0,不是三角形,跳过
        triangle tri(a, b);
        ans = ans + tri;
    }
    printf("A(0,%d),B(0,0),C(%d,0)\n", ans.display_y(), ans.display_x());
    return 0;
}
全部评论

相关推荐

今年读完研的我无房无车无对象,月入还没有过万&nbsp;看到他在朋友圈晒房产证,感叹自己白读了这么多年书
梦想是成为七海千秋:那咋了,双9毕业的现在还没存款呢(因为没念完),高中毕业的去直播带货月入几百万也是完全有可能的,退一万步讲,有些人刚出生父母就给买车买房了,上哪说理去,哪怕是同一个起点也会有截然不同的走向,过好自己的生活就完事了。
点赞 评论 收藏
分享
05-01 22:41
中南大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务