-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathday69.cpp
More file actions
37 lines (33 loc) · 786 Bytes
/
day69.cpp
File metadata and controls
37 lines (33 loc) · 786 Bytes
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
#include <iostream>
#include <queue>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
queue<int> q;
int brr[n];
for (int i = 0; i < n; i++) {
int x;
cin >> x;
q.push(x);
}
for (int i = 0; i < n; i++) cin >> brr[i];
int j = 0, rotations = 0, max_rotations = n * n;
while (!q.empty() && j < n && rotations < max_rotations) {
if (q.front() == brr[j]) {
q.pop();
j++;
rotations = 0;
} else {
q.push(q.front());
q.pop();
rotations++;
}
}
cout << q.size() << endl;
}
return 0;
}