Pagini recente » Cod sursa (job #2285531) | Cod sursa (job #3151747) | Cod sursa (job #2778113) | Cod sursa (job #3215411) | Cod sursa (job #2148061)
#include <fstream>
#include <string.h>
#include <algorithm>
using namespace std;
ifstream in1 ("numar3.in") ;
ifstream in2 ("numar3.in") ;
ofstream out ("numar3.out") ;
char c[4047900] ,present,precedent ;
int n ,poz ,val ,i ;
int main()
{
in1 >> n ;
in1 >> c ;
in1 >> precedent ;
for (i = 2 ; i <= n ; ++ i){
in1 >> present ;
if (present <= precedent)
val ++ ;
else if (present > precedent || i == n){
if (val == 1 && i == n)
poz = n - val + 1 ;
else poz = n - val ;
val = 0 ;
}
if (present > precedent && i == n)
poz = n ;
precedent = present ;
}
in2 >> n ;
for (i = 1 ; i <= poz ; ++ i){
in2 >> precedent ;
out << precedent ;
}
for (i = poz + 1 ; i <= n ; ++ i){
in2 >> precedent ;
c[i - poz - 1] = precedent ;
}
next_permutation(c,c+n - poz) ;
out << c ;
return 0;
}