Pagini recente » Cod sursa (job #1752829) | Cod sursa (job #1617072) | Cod sursa (job #3228216) | Cod sursa (job #1446415) | Cod sursa (job #2219673)
#include <bits/stdc++.h>
using namespace std;
ifstream in("ordine.in");
ofstream out("ordine.out");
std::map<char,int>ap;
int main()
{
char x;
int nr=0;
while(in>>x)
{nr++;
ap[x]++;
}
char last = 'A';
while(nr)
{ bool ok =false;
for (std::map<char,int>::iterator it=ap.begin(); it!=ap.end(); ++it)
if(it->first !=last and it->second>nr/2 and it->second)
{
out<<it->first;
it->second--;
last=it->first;
ok=true;
break;
}
if(!ok)
{
for (std::map<char,int>::iterator it=ap.begin(); it!=ap.end(); ++it)
{
if(it->first!=last and it->second)
{
out<<it->first;
it->second--;
last=it->first;
break;
}
}
}
--nr;
}
return 0;
}