Cod sursa(job #1204643)

Utilizator radu_cebotariRadu Cebotari radu_cebotari Data 3 iulie 2014 16:04:22
Problema Restante Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.53 kb
#include<fstream>
#include<iostream>
#include<string>
using namespace std;
ifstream in("restante.in");
ofstream out("restante.out");

string cuv[40000];
int n;

string qsort(string s,int left,int right)
{

    int i = left,j = right;
    char aux;
    char pivot = s[(i+j)/2];
    while(i <= j){
        while(s[i] < pivot)
            i++;
        while(s[j] > pivot)
            j--;
        if(i <= j){
            aux = s[i];
            s[i] = s[j];
            s[j] = aux;
            i++;
            j--;
        }
    }
    if(left < j) qsort(s,left,j);
    if(right > i) qsort(s,i,right);
    return s;
}

void qsort(int left,int right)
{

    int i = left,j = right;
    string aux;
    string pivot = cuv[(i+j)/2];
    while(i <= j){
        while(cuv[i] < pivot)
            i++;
        while(cuv[j] > pivot)
            j--;
        if(i <= j){
            aux = cuv[i];
            cuv[i] = cuv[j];
            cuv[j] = aux;
            i++;
            j--;
        }
    }
    if(left < j) qsort(left,j);
    if(i < right) qsort(i,right);
}
int main()
{

    in>>n;
    int i;
    for(i = 1 ; i <= n ; i++)
    {
        in>>cuv[i];
        cuv[i] = qsort(cuv[i],0,cuv[i].size()-1);
    }
    qsort(1,n);
    int sol = 0,c = 1,ord = 0;
    string now;
    while(c < n){
        ord = 0;
        now = cuv[c];
        while(now == cuv[c+1]){
            c++;
            ord++;
        }
        if(ord != 0) sol++;
        c++;
    }
    out<<sol;
    return 0;
}