Pagini recente » Cod sursa (job #247955) | Cod sursa (job #880444) | Cod sursa (job #209035) | Cod sursa (job #2857984) | Cod sursa (job #2497425)
#include <fstream>
#include <vector>
#define NMAX 305
using namespace std;
ifstream fin("grozavesti.in");
ofstream fout("grozavesti.out");
struct chestie
{
char ch;
int x1, x2;
};
int mat[NMAX][NMAX], n;
vector<chestie> rez;
void swapC(int c1, int c2)
{
for(int i = 1; i <= n; ++i)
swap(mat[i][c1], mat[i][c2]);
}
void swapL(int l1, int l2)
{
for(int j = 1; j <= n; ++j)
swap(mat[l1][j], mat[l2][j]);
}
int main()
{
fin >> n;
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= n; ++j)
fin >> mat[i][j];
for(int pz = 1; pz <= n; ++pz)
{
int minn = (1 << 30), where = 0;
for(int i = pz; i <= n; ++i)
if(mat[i][i] < minn)
{
minn = mat[i][i];
where = i;
}
if(where != pz){
swapC(pz, where);
swapL(pz, where);
rez.push_back({'C', pz, where});
rez.push_back({'L', pz, where});
}
}
fout << rez.size() << '\n';
for(int i = 0; i < rez.size(); ++i)
fout << rez[i].ch << ' ' << rez[i].x1 << ' ' << rez[i].x2 << '\n';
return 0;
}