A – Swap Odd and Even
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
string s;
cin >> s;
int op = s.size() / 2;
for(int i = 0; i < op; i++) {
swap(s[2*i+1], s[(2*i-1)+1]);
}
cout << s;
return 0;
}
B – Call the ID Number
如果序号x被叫过,什么都不做,否则,打给序号x要叫的人,最后输出没被叫过的。
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
bool st[N];
struct person {
int x, y;
}p[N];
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
for(int i = 1; i <= n; i++) {
p[i].x = i;
cin >> p[i].y;
if(!st[p[i].x]) st[p[i].y] = true;
}
vector<int> res;
for(int i = 1; i <= n; i++) {
if(!st[i]) res.push_back(i);
}
sort(res.begin(), res.end());
cout << res.size() << endl;
for(int i = 0; i < res.size(); i++) {
cout << res[i] << ' ';
}
return 0;
}