题目:
代码和思路:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>int main()
{int n = 0;int m = 0;int arr[10][10] = { 0 };
// 输入行和列scanf("%d%d", &n, &m);int i = 0;int j = 0;//读取数组for (i = 0; i < n; i++){for (j = 0; j < m; j++){scanf("%d", &arr[i][j]);}}int cnt = 0;//操作次数scanf("%d", &cnt);int a = 0;int b = 0;char op = 0;//操作字符for (int i = 0; i < cnt; i++)//循环几次操作几次{scanf(" %c %d %d", &op, &a, &b);if (op == 'r')//交换a和b行{for (j = 0; j < m; j++){int tmp = arr[a - 1][j];//输入的比数组的下标多1,所以要-1arr[a - 1][j] = arr[b - 1][j];arr[b - 1][j] = tmp;}}if (op == 'c')//交换a和b列{for (j = 0; j < n; j++){int tmp = arr[j][a - 1];arr[j][a - 1] = arr[j][b - 1];arr[j][b - 1] = tmp;}}}//打印交换完的数组for (i = 0; i < n; i++){for (j = 0; j < m; j++){printf("%d ", arr[i][j]);}printf("\n");}return 0;
}