Pagini recente » Cod sursa (job #1390557) | Cod sursa (job #754836) | Cod sursa (job #1872465) | Cod sursa (job #225745) | Cod sursa (job #533225)
Cod sursa(job #533225)
// http://infoarena.ro/problema/ordine
#include <fstream>
#include <string>
using namespace std;
ifstream in("ordine.in");
ofstream out("ordine.out");
int lenght;
int letter[200];
char previous,following;
string word;
int main() {
in >> word;
lenght = word.size() - 1;
for(int i=0;i<=lenght;i++)
letter[word[i]]++;
for(int i=0;i<=lenght;i++) {
following = 'z';
for(char currentLetter='a';currentLetter<='z';currentLetter++)
if(letter[currentLetter] == (lenght-currentLetter+1) / 2 + 1) {
following = currentLetter;
break;
}
else
if(letter[currentLetter] && currentLetter != previous && currentLetter < following)
following = currentLetter;
out << following;
letter[following]--;
previous = following;
}
return (0);
}