fork(1) download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8. int t;
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(nullptr);
  11. cin >> t;
  12. for (int i = 0; i < t; i++)
  13. {
  14. int ile;
  15. bool czy_druga{false};
  16. cin >> ile;
  17. int tab[ile];
  18. for (int j = 0; j < ile; j++)
  19. {
  20. tab[j] = j + 1;
  21. }
  22. for (int h = ile; h > 1;)
  23. {
  24. for (int j = 0; j < ile; j++)
  25. {
  26. if ((czy_druga)&&(tab[j] != 0))
  27. {
  28. tab[j] = 0;
  29. czy_druga = false;
  30. h--;
  31. }
  32. else if (tab[j] != 0)
  33. {
  34. czy_druga = true;
  35. }
  36. }
  37. }
  38. for (int j = 0; j < ile; j++)
  39. {
  40. if (tab[j] != 0)
  41. {
  42. cout << tab[j] << '\n';
  43. }
  44. }
  45. }
  46.  
  47. return 0;
  48. }
Success #stdin #stdout 0s 4404KB
stdin
Standard input is empty
stdout
Standard output is empty