Cod sursa(job #127197)

Utilizator marinMari n marin Data 23 ianuarie 2008 16:23:40
Problema Restante Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.62 kb
#include <stdio.h>
#include <string.h>

#define DIM 36008


char w[DIM][20];
long int n,i,ii,jj,j;
char s[20];
int x,y;
int viz[DIM];


void creHeap(char v[DIM][20], long int n){
  long int i,c,p;
  char aux[20];
  for (i=2;i<=n;i++){
    c=i;
    p=i/2;
    while ((p) && (strcmp(v[c],v[p])>0)) {

      strcpy(aux,v[p]);
      strcpy(v[p],v[c]);
      strcpy(v[c],aux);


      c = p;
      p = p/2;
    }
  }
}

void heapSort(char v[DIM][20], long int n){
  long int i,p,c;
  char aux[20];
  creHeap(v,n);
  for (i=n;i>1;i--) {
    strcpy(aux,v[1]);
    strcpy(v[1],v[i]);
    strcpy(v[i],aux);
    p=1;
    c=p*2;
    while (c<=i-1) {
      if ((c+1<=i-1) && (strcmp(v[c+1],v[c])>0))
	c++;
      if (strcmp(v[p],v[c])<0){
	strcpy(aux,v[p]);
	strcpy(v[p],v[c]);
	strcpy(v[c],aux);
      } else break;
      p=c;
      c=p*2;
    }

  }

}


int main(){
  FILE *f = fopen("restante.in","r");
  fscanf(f,"%ld",&n);
  for (i=1;i<=n;i++){
    fscanf(f,"%s",s);
    x = strlen(s);

    for (ii=0;ii<x-1;ii++)
      for (jj=ii+1;jj<=x-1;jj++)
	if (s[ii]>s[jj]) {
	  y = s[ii];
	  s[ii] = s[jj];
	  s[jj] = y;
	}

    strcpy(w[i],s);
    int t=strlen(w[i]);
    while ((w[i][t]>'z')||(w[i][t]<'a')) {
      w[i][t]='\0';
      t--;
    }

  }
  fclose(f);

  heapSort(w,n);

  long int nr=0;
  for (i=2;i<n;i++)
    if ((strcmp(w[i],w[i-1])!=0)&&(strcmp(w[i],w[i+1])!=0)) {
      nr++;
    }
  if (strcmp(w[2],w[1])!=0)
    nr++;
  if (strcmp(w[n],w[n-1])!=0)
    nr++;




  FILE *g = fopen("restante.out","w");
  fprintf(g,"%ld",nr);
  fclose(g);

  return 0;
}