Cod sursa(job #1752511)
Utilizator | Data | 4 septembrie 2016 11:37:50 | |
---|---|---|---|
Problema | Ordine | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.67 kb |
#include <fstream>
using namespace std;
ifstream fin("ordine.in");
ofstream fout("ordine.out");
int a[26]={0};
int n,ok,k,s,i,j;
char b,z;
int main()
{
fin>>b;
while(!fin.eof())
{
++a[b-'a'];
++n;
fin>>b;
}
for(i=0;i<n;i++)
{s=0;
for(j=0;j<26&&s!=1;j++)
{if(a[j]!=0&&j+'a'!=z)
{
a[j]--;ok=1;
for(k=0;k<26;k++)
if(a[k]>(n-i)/2)ok=0;
if(ok)
{fout<<(char)(j+'a');
z=j+'a';s=1;
}
else
a[j]++;
}
}
}
return 0;
}