Gswcp Week - 4
Gswcp Week - 4
Q1:
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
unordered_map<int, int> mp;
vector<int> ar(n);
int swaps = 0;
n=n/2;
for (int i = 0; i < 2 * n; i += 2) {
int first_star = ar[i];
int twin = first_star ^ 1;
if (ar[i + 1] != twin) {
int twin_pos = mp[twin];
swap(ar[i + 1], ar[twin_pos]);
mp[ar[twin_pos]] = twin_pos;
mp[ar[i + 1]] = i + 1;
swaps++;
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
if(t!=0)cout<< "\n";
}
}
Q2:
#include <bits/stdc++.h>
using namespace std;
void solve() {
int m, n;
cin >> m >> n;
vector<string> board(m);
for (int i = 0; i < m; i++) {
cin >> board[i];
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}