Cod sursa(job #104374)

Utilizator BuniakovskiNeguletu Octavian Buniakovski Data 16 noiembrie 2007 01:34:55
Problema Abc2 Scor 0
Compilator cpp Status done
Runda Happy Coding 2007 Marime 1.62 kb
#include <stdio.h>
#include <string.h>
#include <alloc.h>

struct pnod
{
 char a;
 struct pnod *adr;
} ;

struct pnod1
{
 char sir[20];
 struct pnod1 *adr;
};
char c;
char cuv[20];

struct pnod *p;
struct pnod *u;
struct pnod1 *p1;
struct pnod1 *u1;

void citire(char c){
  struct pnod *nou;

  if (p==NULL)
  {
   p=(struct pnod *)
   malloc(sizeof(struct pnod));
   p->a=c;
   u=p;
  }
  else
  {
   nou=(struct pnod *)
   malloc(sizeof(struct pnod ));
   nou->a=c;
   nou->adr=NULL;
   u->adr=nou;
   u=nou;
  }
}
void citire1(char cuv[20]){
  struct pnod1 *nou;

  if (p1==NULL)
  {
   p1=(struct pnod1 *)
   malloc(sizeof(struct pnod1));
   strcpy(p1->sir,cuv);
   p1->sir[strlen(cuv)-1]=NULL;
   u1=p1;
  }
  else
  {
   nou=(struct pnod1 *)
   malloc(sizeof(struct pnod1 ));
   strcpy(nou->sir,cuv);
    nou->sir[strlen(cuv)-1]=NULL;
   nou->adr=NULL;
   u1->adr=nou;
   u1=nou;
  }
}

int main(void){
 FILE *f=fopen("abc.in","r");
 FILE *g=fopen("abc.out","w");
 int i;
 int poz ;
 struct pnod *q;
 int ok;

 poz=0;
 while ((c=fgetc(f))!='\n')
 citire(c) ;
 while (!feof(f))
 {
  fgets(cuv,sizeof(cuv),f);
  citire1(cuv) ;
 }
 while (!p1==NULL)
 {
  ok=0;
  q=p;
  while (q!=NULL)
  {
   while ((q!=NULL) &&(q->a!=p1->sir[0]))
   q=q->adr;
   if (q!=NULL)
   {
    for (i=1;i<=strlen(p1->sir)-1;i++)
    if (p1->sir[i]!=q->adr->a)
    {
     ok=1;
     q=q->adr;
     break;
    }
    else
    q=q->adr;
   }
   else
   ok=1;
   if (ok==0)
   poz++;
   }
  p1=p1->adr;
  }

fprintf(g,"%d",poz);
return (0);
}