fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class quee {
  6. int f;
  7. int b;
  8. int* arr;
  9. public:
  10. quee(int n) {
  11. f = 0;
  12. b = -1;
  13. arr = new int[n];
  14. }
  15. void push(int n) {
  16. arr[++b] = n;
  17. }
  18. int pop() {
  19. if (empty()) return -1;
  20. return arr[f++];
  21. }
  22. int size() {
  23. return b - f + 1;
  24. }
  25. int empty() {
  26. return (b - f) == -1;
  27. }
  28. ~quee() {
  29. delete[] arr;
  30. }
  31. };
  32. int main(void)
  33. {
  34. ios_base::sync_with_stdio(false); cin.tie(NULL);
  35. int n, limit;
  36. cin >> n >> limit;
  37.  
  38. quee q(n * n);
  39. for (int i = 1; i <= n; i++) q.push(i);
  40. cout << "<";
  41. while (q.size() != 1)
  42. {
  43. for (int i = 0; i < limit - 1; i++)
  44. q.push(q.pop());
  45. cout << q.pop() << ", ";
  46. }
  47. cout << q.pop() << ">";
  48. return 0;
  49. }
Success #stdin #stdout 0s 5512KB
stdin
7 3
stdout
<3, 6, 2, 7, 5, 1, 4>