Cod sursa(job #1086684)

Utilizator danmanToma Alex danman Data 18 ianuarie 2014 14:19:06
Problema Episoade Scor 50
Compilator cpp Status done
Runda game01 Marime 1.07 kb
# include <cstdio>
# include <cstring>
# include <cstdlib>
# define infile "episoade.in"
# define outfile "episoade.out"
# define MaxLg 1005
# define MaxN 105
int v[MaxN],poz[MaxN];
char s[MaxLg];
int N,T;
int verif()
{
    int i,M=strlen(s),j,x,y;
    char a[5],b[5];
    for(i=0; i<M; ++i)
      if(s[i]=='>')
      {
         j=i-1;
         while(s[j]<='9' && s[j]>='0') j--;

         strncpy(a,s+j+1,i-j-1);
         a[i-j-1]='\0';
         j=i+1;
         while(s[j]<='9' && s[j]>='0') j++;

         strncpy(b, s+i+1, j-i-1);
         b[j-i-1]='\0';
         x=atoi(a); y=atoi(b);
         if(poz[x]!=poz[y]-1)

         return 0;
      }
    return 1;
}

int main()
{
      freopen(infile, "r", stdin);
      freopen(outfile, "w", stdout);
      scanf("%s", &s);
      scanf("%d%d", &T, &N);
      while (T!=0)
      {
            for(int i=1; i<=N; ++i)
            {
                  scanf("%d",&v[i]);
                  poz[v[i]]=i;
            }
            printf("%d\n",verif());
            --T;
      }
      return 0;
}