Cod sursa(job #125235)

Utilizator gabitzish1Gabriel Bitis gabitzish1 Data 20 ianuarie 2008 12:11:43
Problema Restante Scor 20
Compilator cpp Status done
Runda preONI 2008, Runda 3, Clasa a 9-a Marime 1.18 kb
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int n, contor, c;
char a[36001][17];

int cmp(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;
}


void buble()
{
	int i, ok, j, k;
	char s[17];
	ok = 1;
	while (ok)
	{
	  ok = 0;
	for (i = 1; i < n; i++)
	{
		for (j = 0; j <= 16; j++)
		{
		   if (a[i][j] < a[i+1][j]) break;
                   else
		   if (a[i][j] > a[i+1][j])
		   {
			strcpy(s,a[i]);
			strcpy(a[i],a[i+1]);
			strcpy(a[i+1],s);
			ok = 1;
			break;
		   }
		}
	}
        }

}

void buble2(int j, int n)
{
	char aux;
	int k, i, ok = 1;
	while (ok)
	{ ok = 0;
	for (i = 0; i < n - 1; i++)
		{
			if (a[j][i] > a[j][i + 1])
			{
				aux = a[j][i];
				a[j][i] = a[j][i + 1];
				ok = 1;
				a[j][i + 1] = aux;
			}
		}
	}
}


int main()
{
	freopen("restante.in","r",stdin);
	freopen("restante.out","w",stdout);

	scanf("%d", &n);
	int i, j, l, k, t, ok;
	char s[20];

	for (i = 1; i <= n; i++)
	{
		scanf("%s",&a[i]);
		buble2(i,strlen(a[i]));
	}

	buble();

	for (i = 1; i <= n; i++)
	  if (strcmp(a[i], a[i-1]) && strcmp(a[i],a[i+1])) contor++;
	
	printf("%d\n",contor);
	return 0;
}