Pagini recente » Cod sursa (job #1836459) | Cod sursa (job #249758) | Cod sursa (job #1638364) | Cod sursa (job #2773152) | Cod sursa (job #2219606)
#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]++;
}
bool prim=false;
char y;
while(nr--)
{ if(!prim)
{
prim=true;
for (std::map<char,int>::iterator it=ap.begin(); it!=ap.end(); ++it)
{y=it->first;it->second--; break;
}
out<<y;
}
else
for (std::map<char,int>::iterator it=ap.begin(); it!=ap.end(); ++it)
{ if(it->second && it->first!=y)
{
out << it->first; it->second--; y=it->first; break;
}
}
}
return 0;
}