Pagini recente » Istoria paginii runda/oni_2017_cl10_ziua2 | Cod sursa (job #1034716) | Cod sursa (job #478869) | Cod sursa (job #496740) | Cod sursa (job #163931)
Cod sursa(job #163931)
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
int n,l,nro=0,ok;
char c[20],mat[20][36001];
void scan()
{
int inj,gata;
char aux[20];
freopen("restante.in", "r",stdin);
freopen("restante.out", "w",stdout);
scanf("%d", &n);
for(int i=1;i<=n;++i)
{
scanf("%s", &c);
l=strlen(c);
sort(c,c+l);
mat[i][0]=l;
for(int j=0;j<l;++j)
mat[i][j+1]=c[j];
}
inj=n;
while(inj>1)
{
inj/=2;
do{
gata=1;
for(int i=1;i<=n-inj;i++)
if(mat[i][1]>mat[i+inj][1])
{
for(int j=1;j<=mat[i][0];++j)
aux[j]=mat[i][j];
aux[0]=mat[i][0];
for(int j=1;j<=mat[i+inj][0];++j)
mat[i][j]=mat[i+inj][j];
mat[i][0]=mat[i+inj][0];
for(int j=1;j<=aux[0];++j)
mat[i+inj][j]=aux[j];
mat[i+inj][0]=aux[0];
gata=0;
}
}
while(!gata);
}
}
void solve()
{
for(int i=2;i<=n;++i)
{
ok=0;
for(int j=1;j<=mat[i][0];++j)
if(mat[i][j]!=mat[i-1][j])
{ok=1; break;}
if(ok)
++nro;
}
}
void print()
{ printf("%d\n", nro);}
int main()
{
scan();
solve();
print();
return 0;
}