Cod sursa(job #1765650)

Utilizator LaurIleIle Laurentiu Daniel LaurIle Data 26 septembrie 2016 21:30:12
Problema Ordine Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.45 kb
#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;

bool valid(string s)
{
    for(int i=0; i<s.size()-1; ++i)
        if(s[i]==s[i+1])
        return 0;
    return 1;
}

int main()
{   ifstream f("ordine.in");
    string s,c;
    f >> s;
    do
    {
        if(valid(s))
        c=s;
    } while(prev_permutation(s.begin(), s.end()));

    ofstream g("ordine.out");
    g << c << "\n";
    return 0;
}