Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "BigIntegerAlgorithms.hh"
- #include <iostream>
- #include <fstream>
- #include <stdlib.h>
- #include <vector>
- #include <string>
- using namespace std;
- //Необходимо реализовать данный метод
- //Вся информация о задаче доступна в тексте задачи и в слайдах презентации к семинару(в ЛМС)
- void GetNext(vector<int>& arr, int N){
- int i=N;
- while (i>0 && arr[i]<arr[i-1])
- --i;
- int j=N;
- while(arr[j]<arr[i-1])
- --j;
- swap(arr[i-1], arr[j]);
- for(j=0; j<=((N+1-i)/2)-1; ++j)
- swap(arr[i + j], arr[N - j]);
- }
- static string get_day(int N,int k) {
- vector<int> arr(N);
- vector<int> arrt(N);
- int q = 0;
- for (int i = 0; i < N; ++i) {
- arr[i] = i + 1;
- arrt[i] = N - i;
- }
- if (q != 1) {
- do {
- GetNext(arr, N - 1);
- if(k-1==++q)
- break;
- } while (arr != arrt);
- }
- string str;
- for(int i=0; i<N; ++i)
- str+=to_string(arr[i]) + ' ';
- str = str.substr(0, str.length()-1);
- return str;
- }
- int main(int argc, const char * argv[]) {
- int N,K;
- fstream fin;
- fstream fout;
- fin.open("input.txt",ios::in);
- fout.open("output.txt",ios::out);
- if(fin.is_open()) {
- string str;
- getline(fin,str);
- N = atoi( str.c_str());
- getline(fin,str);
- K = atoi( str.c_str());
- fout << get_day(N,K)<< endl;
- fout.close();
- fin.close();
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement