ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1837. Число Исенбаева

why WA #5 give me some tests
Послано 219 20 окт 2011 21:21
#include <iostream>
#include <string.h>

using namespace std;
int orni[10000]={-1},ornini;
char a[]="Isenbaev";
int main()
{

    int n,i,k,l,q,qator[500]={0},s,j,r,r1,r2;
    bool f=0;
    char ism[10000][30],ismi[500][4][30],soz[30];
    cin>>n;
    for(i=1;i<=n;i++)
    for(j=1;j<=3;j++){cin>>ismi[i][j]; if(f==0&&strcmp(ismi[i][j],a)==0){f=1;r1=i;r2=j;}}

    // agar Isenbaev bo'lsa tekshiriladi;
    if(f==1)
    {
        // cout<<1<<endl;
       strcpy(soz,ismi[r1][r2]);
       strcpy(ismi[r1][r2],ismi[1][1]);
       strcpy(ismi[1][1],soz);j=2;
       for(i=1;i<=3;i++)
       {
                        if(i!=r2)
                        {
                                strcpy(soz,ismi[r1][i]);
                                strcpy(ismi[r1][i],ismi[1][j]);
                                strcpy(ismi[1][j],soz);
                                j++;
                        }
       }
    orni[0]=0;
    strcpy(ism[0],ismi[1][1]);
    //ism[0]=ismi[1][1];
    l=0;
    for(k=0;k<=l;k++){
    for (i=1;i<=n;i++)
    {
        for(j=1;j<=3;j++)
        if (qator[i]==0&&strcmp(ism[k],ismi[i][j])==0)
        {
           for(q=1;q<=3;q++)
           {
                            s=true;
                            strcpy(soz,ismi[i][q]);

                            for(r=0;r<=l;r++)
                            {
                                             if(strcmp(ism[r],soz)==0)s=false;
                            }
                            if(s){l=l+1;strcpy(ism[l],soz); orni[l]=orni[k]+1;}

           }
           qator[i]=1;
        }
    }}
    for(i=1;i<=n;i++)
    {
                     if(qator[i]==0)
                     {
                                 for(j=1;j<=3;j++)
                                 {
                                                  s=true;
                                                  strcpy(soz,ismi[i][j]);
                                                  for(k=0;k<=l;k++)
                                                  {
                                                         if(strcmp(ism[k],soz)==0)s=false;
                                                  }
                                                  if(s){l=l+1;strcpy(ism[l],soz);orni[l]=-1;}
                                 }
                     }
    }

    }

    // Isenbaev bo'lmasa ko'rib chiqamiz;

    else
    {
         l=-1;
         for(i=1;i<=n;i++)
         {


                                 for(j=1;j<=3;j++)
                                 {
                                                  s=true;
                                                  strcpy(soz,ismi[i][j]);
                                                  for(k=0;k<=l;k++)
                                                  {
                                                         if(strcmp(ism[k],soz)==0)s=false;
                                                  }
                                                  if(s){l=l+1;strcpy(ism[l],soz);orni[l]=-1;}
                                 }

         }

    }



    for(i=1;i<=l;i++)
    {
           j=i;
           while(j>0&&strcmp(ism[j],ism[j-1])<0)
           {

                                          strcpy(soz,ism[j]);  ornini=orni[j];
                                          strcpy(ism[j],ism[j-1]);orni[j]=orni[j-1];
                                          strcpy(ism[j-1],soz);orni[j-1]=ornini;
                                          j--;
           }
    }
    for(i=0;i<=l;i++){cout<<ism[i]<<" ";if(orni[i]!=-1)cout<<orni[i]; else cout<<"undefined"; cout<<endl;}

   return 0;
}