Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <set>
- using namespace std;
- int main()
- {
- int n;
- cin >> n;
- vector<int> v;
- for(int i = 1; i <= n; i++){
- v.push_back(i);
- }
- while((int) v.size() > 1) {
- vector<int> nepacateni;
- for(int i = 0; i < (int) v.size(); i++) {
- if(i % 2 == 1) {
- cout << v[i] << " ";
- }
- else {
- nepacateni.push_back(v[i]);
- }
- }
- if((int) v.size() % 2 == 0) {
- v = nepacateni;
- }
- else {
- int last_element = nepacateni[(int) nepacateni.size() - 1];
- v.clear();
- v.push_back(last_element);
- for(int i = 0; i < (int) nepacateni.size() - 1; i++) {
- v.push_back(nepacateni[i]);
- }
- }
- }
- cout << v[0] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement