Cod sursa(job #1213230)

Utilizator hopingsteamMatraguna Mihai-Alexandru hopingsteam Data 27 iulie 2014 16:24:39
Problema Restante Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.23 kb
#include    <iostream>
#include    <fstream>
#include    <algorithm>
#include    <cstring>

using namespace std;

ifstream fin("restante.in");
ofstream fout("restante.out");

char word[36000][17];

void quickSort(int left, int right) 
{
    int i = left, j = right;
    char tmp[17];
    int pivot = (left + right) / 2;
    while (i <= j) 
    {
        while(strcmp(word[i],word[pivot]))
            i++;
        while(strcmp(word[j],word[pivot]))
            j--;
        if (i <= j) 
        {
            strcpy(tmp, word[i]);
            strcpy(word[i], word[j]);
            strcpy(word[j], tmp);
            i++;
            j--;
        }
      };
 
      if (left < j)
            quickSort(left, j);
      if (i < right)
            quickSort(i, right);
}

void read()
{
    int n, length;
    fin >> n;
    for(int i = 0; i < n; i++)
        fin >> word[i];
        
    for(int i = 0; i < n; i++)
    {
        length = strlen(word[i]);
        sort(word[i], word[i] + length);
    }
    
    quickSort(0, n-1);
    
    int x = 0;
    for(int i = 0; i < n - 1; i++)
    {
        if(strcmp(word[i],word[i+1])) x += 1;
    }
    fout << x;
}

int main()
{
    read();
    return 0;
}