解题思路:
注意事项:
参考代码:
#include<malloc.h> #include<stdio.h> int main() { int N, M,*p1,i = 0,*p[2],t; scanf("%d%d", &N, &M); p1 = (int*)malloc(sizeof(int) * N); p[0] = (int*)malloc(sizeof(int) * M); p[1] = (int*)malloc(sizeof(int) * M); for (; i < N; scanf("%d", &p1[i]), i++); for (i = 0; i < M; scanf("%d%d",&p[0][i],&p[1][i]), i++); for (i = 0; i < M; i++) { if(p[0][i] != p[1][i]) { t = p1[p[0][i]-1]; p1[p[0][i]-1] = p1[p[1][i]-1]; p1[p[1][i]-1] = t; } } for (i = 0; i < N; printf("%d \n", p1[i]), i++); }
0.0分
2 人评分
#include "stdio.h" int main() { int m, n, x1, x2, k; scanf("%d%d", &n, &m); int a[n]; for (int i = 0; i < n; i++) scanf("%d", &a[i]); for (int j = 0; j < m; j++) { scanf("%d%d", &x1, &x2); if (x1 != x2) { k = a[x1 - 1]; a[x1 - 1] = a[x2 - 1]; a[x2 - 1] = k; } } for (int i = 0; i < n; i++) { printf("%d\n", a[i]); } return 0; }
harder 2022-03-30 09:37:07 |
没辣么复杂吧
sqmw 2022-09-26 05:23:01 |
确实没有,就是锻炼一下堆空间的使用