Cod sursa(job #3363434)

Utilizator alexm749Musat Alexandru Nicolae alexm749 Data 17 august 2026 23:42:07
Problema Restante Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.07 kb
#include <iostream>
#include <fstream>
#include <cstring>
#include <algorithm>

using namespace std;

ifstream f("restante.in");

ofstream g("restante.out");

int nr,fv[26];
bool V[36000];
struct cv
{
    char s[17];
};
cv s[36000];
bool compara(const cv a, const cv b)
{
    return strcmp(a.s,b.s)<0;
}
int main()
{
    int n;
    f>>n;
    f.get();
    for(int i=0; i<n; i++)
    {
        f.getline(s[i].s,17);
        for(int j=0; j<26; j++)fv[j]=0;
        for(int j=0; s[i].s[j]!='\0'; j++)fv[int(s[i].s[j]-97)]++;
        int k=0;
        for(int j=0; j<26; j++)
        {
            while(fv[j]!=0)
            {
                s[i].s[k++]=char(j+97);
                fv[j]--;
            }
        }
    }
    sort(s,s+n,compara);
    if(n==1)g<<1;
    else
    {
        if(strcmp(s[0].s,s[1].s)!='\0')nr++;
        for(int i=1;i<n-1;i++)
        {
            if(strcmp(s[i].s,s[i-1].s)!='\0'&&strcmp(s[i].s,s[i+1].s)!='\0')nr++;
        }
        if(strcmp(s[n-1].s,s[n-2].s)!='\0')nr++;
    }
    g<<nr;
    return 0;
}