题解 | #有序序列插入一个整数#
矩阵交换
http://www.nowcoder.com/practice/ec44d4ff8c794b2f9205bdddbde96817
#include<iostream>
using namespace std;int main()
{
int n, m, i, j, k, a, b;
int arr[10][10] = { 0 };
int z[10] = { 0 };
char t;
cin >> n >> m;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
cin >> arr[i][j];
// 输入交换次数
cin >> k;
while (k)
{
cin >> t >> a >> b;
// 交换
if (t == 'r')
{
for (j = 0; j < m; j++)
{
z[j] = arr[a - 1][j];
arr[a - 1][j] = arr[b - 1][j];
arr[b - 1][j] = z[j];
}
}
else if (t == 'c')
{
for (i = 0; i < n; i++)
{
z[i] = arr[i][a - 1];
arr[i][a - 1] = arr[i][b - 1];
arr[i][b - 1] = z[i];
}
}
k--;
}
for (i = 0; i < n; i++)
{
for (j = 0; j < m; j++)
cout << arr[i][j] << ' ';
cout << endl;
}
system("pause");
return 0;
}