#include<bits/stdc++.h>
using namespace std;
int main()
{
int t, n, m, i, j, k, r1, r2, c1, c2, l = 1;
cin >> t;
while(t--)
{
cin >> n;
int a[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
char ch;
cin >> ch;
a[i][j] = ch - 48;
}
}
cin >> m;
string st;
for(k=1;k<=m;k++)
{
cin >> st;
if(st == "transpose")
{
int b[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[j][i] = a[i][j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j] = b[i][j];
}
}
}
else if(st == "inc")
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]++;
if(a[i][j] > 9)
a[i][j] = a[i][j]%10;
}
}
}
else if(st == "dec")
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]--;
if(a[i][j] < 0)
a[i][j] = a[i][j] + 10;
}
}
}
else if(st == "row")
{
cin >> r1 >> r2;
for(i=0;i<n;i++)
swap(a[r1-1][i], a[r2-1][i]);
}
else if(st == "col")
{
cin >> c1 >> c2;
for(i=0;i<n;i++)
{
swap(a[i][c1-1], a[i][c2-1]);
}
}
}
cout << "Case #" << l++ << "\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout << a[i][j];
}
cout << "\n";
}
cout << "\n";
}
return 0;
}
using namespace std;
int main()
{
int t, n, m, i, j, k, r1, r2, c1, c2, l = 1;
cin >> t;
while(t--)
{
cin >> n;
int a[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
char ch;
cin >> ch;
a[i][j] = ch - 48;
}
}
cin >> m;
string st;
for(k=1;k<=m;k++)
{
cin >> st;
if(st == "transpose")
{
int b[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
b[j][i] = a[i][j];
}
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j] = b[i][j];
}
}
}
else if(st == "inc")
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]++;
if(a[i][j] > 9)
a[i][j] = a[i][j]%10;
}
}
}
else if(st == "dec")
{
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
a[i][j]--;
if(a[i][j] < 0)
a[i][j] = a[i][j] + 10;
}
}
}
else if(st == "row")
{
cin >> r1 >> r2;
for(i=0;i<n;i++)
swap(a[r1-1][i], a[r2-1][i]);
}
else if(st == "col")
{
cin >> c1 >> c2;
for(i=0;i<n;i++)
{
swap(a[i][c1-1], a[i][c2-1]);
}
}
}
cout << "Case #" << l++ << "\n";
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
cout << a[i][j];
}
cout << "\n";
}
cout << "\n";
}
return 0;
}
Comments
Post a Comment