Cod sursă (job #317000)

Utilizator avatar sabinanton Anton Sabin-Viorel sabinanton IP ascuns
Problemă Domino Compilator cpp | 0,77 kb
Rundă Arhiva de probleme Status evaluat
Dată 16 oct. 2017 16:08:03 Scor 8
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("domino.in");
ofstream fout("domino.out");
int n,v[10001],k,x[10001],a,b,rot;
bool t[10001];
int main()
{
int i,j,vf=0,k1,k2,s,vf1,d;
   fin>>n>>k1>>k2;
   x[vf]=0;
   v[vf]=0;
   for(i=1;i<=n;i++)
   {
        fin>>s>>d;
        while(max(s,d)>v[vf]&&vf>0&&k2>0)
        {
            vf--;
            k2--;
        }
        //cout<<vf<<" "<<k1<<endl;
        vf++;
        if(s<d)
        {
            rot++;
            v[vf]=d;
            x[vf]=s;
        }
        else{
         v[vf]=s;
         x[vf]=d;
        }
   }
   for(i=vf;i>0;i--)
   {
        if(rot>k1)
        {
        int aux=v[i];
        v[i]=x[i];
        x[i]=aux;
        }
   }
   for(i=1;i<=vf;i++)
  fout<<v[i]<<x[i];

    return 0;
}