题解 | #牛牛的平面向量#

牛牛的平面向量

https://www.nowcoder.com/practice/0e0d472d6a30469ab90d8b0aef7f81fe

#include <stdio.h>
#include <stdlib.h>

typedef struct node {
    int x, y;
} Vector;

Vector AddVector(Vector* arr, int n) {
    Vector ans = {0, 0};
    for (int i = 0; i < n; i++) {
        ans.x += (arr + i) -> x;
        ans.y += (arr + i) -> y;
    }
    return ans;
}

int main() {
    int n;
    scanf("%d", &n);
    Vector* array = (Vector*)malloc(n * sizeof(Vector));
    for (int i = 0; i < n; i++) {
        scanf("%d %d", & (array + i)->x, & (array + i)->y);
    }
    Vector ans = AddVector(array, n);
    printf("%d %d", ans.x, ans.y);
    return 0;
}

全部评论

相关推荐

01-11 08:47
门头沟学院 Java
程序员花海_:所以看起来还是实习的好处多 给导师打黑工能学到什么
点赞 评论 收藏
分享
2025-12-30 16:42
同济大学 C++
仁狂躁使者:哎呀,不用担心,我当时配环境配了两天,项目捋不清就问问导师能不能用ai,慢慢就清了,会好起来的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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