57852023-09-27 22:55:44AncsaKövetkező permutáció (50 pont)cpp11Wrong answer 0/5012ms4840 KiB
#include <bits/stdc++.h>

using namespace std;
/*
8
2 3 5 8 7 6 4 1
*/
int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin>>a.at(i);

    vector<int> vege;
    //a vector vegerol levesszuk a csokkeno reszt
    int index=n-1;   //2 3 5 4 1

    while(a.at(index-1)>a.at(index))
    {
        vege.push_back(a.at(index));
        index--;
    }
    vege.push_back(a.at(index));

    for(int x:vege)
        cout<<x<<" ";
/*
    sort(vege.begin(),vege.end(),greater<int>());
    cout<<endl;
    for(int x:vege)
        cout<<x<<" ";
*/
    cout<<"cserelni kell a "<<a.at(index-1)<<endl;
    int j=0;
    while(a.at(index-1)>vege.at(j))
        j++;

            int temp=vege.at(j);
            vege.at(j)=a.at(index-1);
            a.at(index-1)=temp;

    cout<<endl;
    for(int x:a)
      cout<<x<<" ";
    cout<<endl;
    for (int x:vege)
        cout<<x<<" ";
    vector<int> kicsik, nagyok;
    for(int x:vege)
    {
        if(x>a.at(index-1))
            nagyok.push_back(x);
        else
            kicsik.push_back(x);
    }
    cout<<endl;
    for(int x:nagyok)
      cout<<x<<" ";
    cout<<endl;
    for(int x:kicsik)
      cout<<x<<" ";
    int hol=kicsik.size()-1;
    for (int i=index;i<index+kicsik.size();i++)
    {
        a.at(i)=kicsik.at(hol);
        hol--;
    }
    index+=kicsik.size();
    hol=0;
    for(int i=index;i<n;i++)
    {
        a.at(i)=nagyok.at(hol);
        hol++;
    }
    cout<<endl;
    for(int x:a)
        cout<<x<<" ";












    //cout << "Hello world!" << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/50
1Wrong answer0/03ms1832 KiB
2Wrong answer0/06ms1936 KiB
3Wrong answer0/12ms2076 KiB
4Wrong answer0/12ms2160 KiB
5Wrong answer0/12ms2296 KiB
6Wrong answer0/12ms2512 KiB
7Wrong answer0/23ms2764 KiB
8Wrong answer0/23ms2916 KiB
9Wrong answer0/23ms3124 KiB
10Wrong answer0/23ms3376 KiB
11Wrong answer0/12ms3464 KiB
12Wrong answer0/12ms3460 KiB
13Wrong answer0/12ms3420 KiB
14Wrong answer0/13ms3420 KiB
15Wrong answer0/33ms3664 KiB
16Wrong answer0/33ms3764 KiB
17Wrong answer0/33ms3880 KiB
18Wrong answer0/33ms3972 KiB
19Wrong answer0/36ms4116 KiB
20Wrong answer0/37ms4328 KiB
21Wrong answer0/37ms4416 KiB
22Wrong answer0/38ms4416 KiB
23Wrong answer0/38ms4416 KiB
24Wrong answer0/38ms4400 KiB
25Wrong answer0/212ms4840 KiB
26Wrong answer0/28ms4604 KiB