Cod sursa(job #1619286)

Utilizator stefzahZaharia Stefan Tudor stefzah Data 28 februarie 2016 14:50:39
Problema Ordine Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
#include <fstream>
#include <cstring>
using namespace std;
ifstream fin("ordine.in");
ofstream fout("ordine.out");
char s[1000005];
int a[30],k,n;
char st[1000005];
void Afisare()
 {int i;
     for(i=0;i<n;i++)
        fout<<st[i];
 }
void Back(int top)
         {int i;
          if(k==0)
          {
              if(top==n){Afisare();k=1;}
          else{for(i=1;i<=26;i++)
                  {if(a[i]>0&&st[top-1]!=i+96){st[top]=i+96;a[i]--;
                   Back(top+1);
                   a[i]++;
                  }
                  }
              }
          }
         }
int main()
{int i;
 fin>>s;
n=strlen(s);
 for(i=0;i<n;i++)
    {a[s[i]-96]++;
    }
 Back(0);
}