Blame view

SearchingSortingandBasicDataStructures/Deque/Problem1/TicketCounter.cpp 939 Bytes
eb0b70f67   Ronaldo   Updating the dire...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
  //
  // Created by ronal on 2/11/2023.
  // Problem description link.
  // https://practice.geeksforgeeks.org/problems/ticket-counter/0
  
  #include <bits/stdc++.h>
  using namespace std;
  
  int TicketCounter(deque<int> &Deque, int K){
  
      while(Deque.size() != 1){
          for(int i = 0; i < K; i++){
              if(Deque.size() == 1){
                  break;
              }else{
                  Deque.pop_front();
              }
          }
  
          for(int j = 0; j < K; j++){
              if(Deque.size() == 1){
                  break;
              }else{
                  Deque.pop_back();
              }
          }
      }
      return Deque.front();
  }
  
  int main() {
      int tests, N, K;
      deque<int> Deque;
  
      cin >> tests;
      for(int i = 0; i < tests; i++){
          cin >> N >> K;
          for(int j = 1; j <= N; j++){
              Deque.push_back(j);
          }
          cout << TicketCounter(Deque, K) << "
  ";
          Deque.clear();
      }
      return 0;
  }