Cod sursă (job #686006)

Utilizator avatar morariu.tudor Morariu Tudor morariu.tudor IP ascuns
Problemă Arbperm Compilator cpp-32 | 3.27 kb
Rundă Arhiva de probleme Status evaluat
Dată 6 ian. 2023 15:40:26 Scor 0
/***
*    ███╗   ███╗ ██████╗ ██████╗  █████╗ ██████╗ ██╗██╗   ██╗████████╗██╗   ██╗██████╗  ██████╗ ██████╗ 
*     ████╗ ████║██╔═══██╗██╔══██╗██╔══██╗██╔══██╗██║██║   ██║╚══██╔══╝██║   ██║██╔══██╗██╔═══██╗██╔══██╗
*      ██╔████╔██║██║   ██║██████╔╝███████║██████╔╝██║██║   ██║   ██║   ██║   ██║██║  ██║██║   ██║██████╔╝
*       ██║╚██╔╝██║██║   ██║██╔══██╗██╔══██║██╔══██╗██║██║   ██║   ██║   ██║   ██║██║  ██║██║   ██║██╔══██╗
*        ██║ ╚═╝ ██║╚██████╔╝██║  ██║██x║  ██║██║  ██║██║╚██████╔╝██╗██║   ╚██████╔╝██████╔╝╚██████╔╝██║  ██║
*         ╚═╝     ╚═╝ ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝ ╚═════╝ ╚═╝╚═╝    ╚═════╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═╝
*                                                                                                       
*/
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector> 

using namespace std;
 
ifstream fin("arbperm.in");
ofstream fout("arbperm.out");

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void debug(vector<int> v)
{
    for(int i = 0;i < v.size();i++) cout << v[i] << ' ';
    cout << endl;
}
int firstDigit(int n)
{
    while (n >= 10) n /= 10;
    return n;
}

string decToBin(int decimal, int sz)
{
    string ans;
    int it = 0;
    while(decimal)
    {
        ans.push_back(decimal % 2 + '0');
        decimal /= 2;
    }
    reverse(ans.begin(), ans.end());
    while(ans.size() < sz) ans.insert(ans.begin(), '0');

    return ans;
}

int main()
{
    int n, k; fin >> n >> k;
    vector<int> v(n);

    for(int i = 0;i < n;fin >> v[i++]);

    int pos = 0;

    for(int i = 0;i < n;i++)
    {
        if(v[i] == n)
        {
            pos = i;
            break;
        }
    }

    int a = n - pos - 1;


    if(pos + k < n)
    {
        swap(v[pos], v[pos + k]);
    }

    for(int i = 0;i < n;i++) fout << v[i] << " ";
}