Pagini recente » Istoria paginii runda/ergeshs/clasament | Cod sursa (job #1206326) | Cod sursa (job #194693) | Cod sursa (job #2028345) | Cod sursa (job #533247)
Cod sursa(job #533247)
#include <fstream>
#include <string>
using namespace std;
ifstream in("ordine.in");
ofstream out("ordine.out");
string word;
int letter[200];
int i,lenght;
char currentLetter,previous,following;
int main() {
in >> word;
lenght = word.size() - 1;
for (i = 0; i <= lenght; ++i)
letter[word[i]]++;
previous = ' ';
for (i = 0; i <= lenght; ++i) {
following = 'z';
for (currentLetter = 'a'; currentLetter <= 'z'; ++currentLetter)
if (letter[currentLetter]==(lenght-i+1)/2+1) {
following = currentLetter;
break;
}
else
if (letter[currentLetter]!=0 && currentLetter!=previous && currentLetter<following)
following = currentLetter;
out << following;
letter[following]--;
previous = following;
}
return 0;
}