Cod sursa(job #807528)

Utilizator Vally77FMI Calinescu Valentin Gelu Vally77 Data 4 noiembrie 2012 21:10:57
Problema A+B Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.58 kb
#include <iostream>
#include <fstream>
#include <math.h>
using namespace std;
int nivel,stn[100000],dr[100000];
string coord[100000][2];
int main()
{
    int n,m,i,x,r;
    string dir;
    ifstream ka("in.txt");
    ofstream ki("out.txt");
    ka>>n;
    for(i=0;i<n;i++)
    {
        ka>>m>>dir;
        if(dir=="S")
        {
            stn[i]=nivel+m;
            dr[i]=nivel;
            coord[i][0]="S";
            coord[i][1]="S";
            nivel=(nivel+nivel+m)/2;
        }
        else
        {
            dr[i]=nivel+m;
            stn[i]=nivel;
            coord[i][0]="D";
            coord[i][1]="D";
            nivel=(nivel+nivel+m)/2;
        }
            for(r=0;r<=i;r++)
            {
              if(dir=="S")
              {
                  if((m/2>dr[r])and(coord[r][1]=="S"))
                  {
                      dr[r]=m/2-dr[r];
                      coord[r][1]="D";
                  }
                  else if((m/2<=dr[r])and(coord[r][1]=="S"))
                      dr[r]=dr[r]-m/2;
                 else if(coord[r][1]=="D")
                  {
                      dr[r]=dr[r]+m/2;
                  }

                if((m/2>stn[r])and(coord[r][0]=="S"))
                  {
                      stn[r]=m/2-stn[r];
                      coord[r][0]="D";
                  }
                 else if((m/2<=stn[r])and(coord[r][0]=="S"))
                      stn[r]=stn[r]-m/2;
                 else if(coord[r][0]=="D")
                  {
                      stn[r]=stn[r]+m/2;
                  }
              }
              else
              {
                  if((m/2>stn[r])and(coord[r][0]=="D"))
                  {
                      stn[r]=m/2-stn[r];
                      coord[r][0]="S";
                  }
                  else if((m/2<=stn[r])and(coord[r][0]=="D"))
                      stn[r]=stn[r]-m/2;
                  else if(coord[r][0]=="S")
                  {
                      stn[r]=stn[r]+m/2;
                  }

                  if((m/2>dr[r])and(coord[r][1]=="D"))
                  {
                      dr[r]=m/2-dr[r];
                      coord[r][1]="S";
                  }
                  else if((m/2<=dr[r])and(coord[r][1]=="D"))
                      dr[r]=dr[r]-m/2;
                  else if(coord[r][1]=="S")
                  {
                      dr[r]=dr[r]+m/2;
                  }
              }

            }
    }
    ki<<nivel<<'\n';
    ka>>x;
    ki<<stn[x-1]<<" "<<coord[x-1][0]<<'\n'<<dr[x-1]<<" "<<coord[x-1][1];
}