Cod sursa(job #1064206)

Utilizator robertstrecheStreche Robert robertstreche Data 21 decembrie 2013 17:34:29
Problema Grozavesti Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <fstream>
#include <algorithm>

using namespace std;

ifstream f("grozavesti.in");
ofstream g("grozavesti.out");

struct el {int y;int x;};

el sol[30001];

long long v[30001],n,ok,ma,i,j,nr,x,p;

int main()
{

   f>>n;

   for (i=1;i<=n;i++)
    for (j=1;j<=n;j++)
      {
          f>>x;
          if (i==j)
           v[++nr]=x;
      }
    //for (i=1;i<=n;i++)
      //g<<v[i]<<" ";
      nr=0;
   for (i=n;i>=2;i--)
     {
           ma=v[1];
           p=1;
         for (j=2;j<=i;j++)
           if (v[j]>ma)
            {
                ma=v[j];
                p=j;
            }
           if (p!=i)
            {
                sol[++nr].y=i;
                sol[nr].x=p;
                swap(v[i],v[p]);
            }

     }
    g<<2*nr<<'\n';
    for (i=1;i<=nr;i++)
      g<<"C "<<sol[i].y<<" "<<sol[i].x<<'\n'<<"L "<<sol[i].y<<" "<<sol[i].x<<'\n';
   f.close();
   g.close();
}