速热 发表于 2024-3-7 10:09:43

有C语言大佬能看看这道题吗

求用C语言,不要用C++

FishC 发表于 2024-3-7 10:09:54

当然可以帮助你解答C语言的问题!请告诉我你遇到了什么困惑,我会尽力帮你解答。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。

不二如是 发表于 2024-3-7 10:41:19

用 Python 解决的:

def calculate_final_positions(n, m, movements, start_positions):
    # 计算最终位置
    final_positions = []
    for x, y in start_positions:
      for dx, dy in movements:
            x += dx
            y += dy
      final_positions.append((x, y))
    return final_positions

# 示例输入
n, m = 3, 2# 移动次数和点的数量
movements = [(10, 10), (0, 0), (10, -20)]# 移动的变化量
start_positions = [(1, -1), (0, 0)]# 起始位置

# 计算最终位置
final_positions = calculate_final_positions(n, m, movements, start_positions)

# 输出最终位置
for position in final_positions:
    print(position)# 这会打印每个起始点的最终位置

C 语言也可以:

#include <stdio.h>

// 结构体用于存储点的坐标
typedef struct {
    int x;
    int y;
} Point;

// 函数用于计算最终位置
void calculate_final_positions(int n, int m, Point movements[], Point start_positions[]) {
    for (int i = 0; i < m; ++i) {
      Point final_position = start_positions;
      for (int j = 0; j < n; ++j) {
            final_position.x += movements.x;
            final_position.y += movements.y;
      }
      // 打印最终位置
      printf("%d %d\n", final_position.x, final_position.y);
    }
}

int main() {
    int n, m;
    scanf("%d %d", &n, &m); // 读取移动次数和点的数量

    Point movements; // 存储所有移动的数组
    for (int i = 0; i < n; ++i) {
      scanf("%d %d", &movements.x, &movements.y); // 读取移动的变化量
    }

    Point start_positions; // 存储所有起始位置的数组
    for (int i = 0; i < m; ++i) {
      scanf("%d %d", &start_positions.x, &start_positions.y); // 读取起始位置
    }

    // 计算并打印所有点的最终位置
    calculate_final_positions(n, m, movements, start_positions);

    return 0;
}
页: [1]
查看完整版本: 有C语言大佬能看看这道题吗