A
Process the characters in order: replace A with Alpha, B with Bravo, and C with Charlie. Remember to read $$$N$$$ (I got a time penalty here).
Code
#include<bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int n;
cin>>n;
string s;
cin>>s;
for(char c:s){
if(c=='A'){
cout<<"Alpha ";
}else if(c=='B'){
cout<<"Bravo ";
}else cout<<"Charlie ";
}
return 0;
}
B
We can use a boolean array $$$\texttt{vis}$$$. For each input $$$A_i$$$, set $$$\texttt{vis}_{A_i}=1$$$. For each subsequent $$$X_i$$$ and $$$Y_i$$$, set $$$\texttt{vis}_{X_i}=0$$$ and $$$\texttt{vis}_{Y_i}=1$$$. Finally, output $$$\sum\limits_{i=1}^{100} \texttt{vis}_i$$$.
Code
#include<bits/stdc++.h>
using namespace std;
int a[int(5e5+5)];
bitset<int(5e5+5)> vis;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
vis[a[i]]=1;
}
for(int i=1,x,y;i<=m;i++){
cin>>x>>y;
vis[x]=0,vis[y]=1;
}
for(int i=1;i<=100;i++){
if(vis[i])cout<<i<<' ';
}
return 0;
}
C
If we encounter an o, then we add $$$1$$$ to the answer, and then change this cell and every cell after it at intervals of $$$k$$$ to ..
Code
#include<bits/stdc++.h>
using namespace std;
int a[int(5e5+5)];
bitset<int(5e5+5)> vis;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int n,k,ans=0;
string s;
cin>>n>>k>>s;
for(int i=0;i<n;i++){
if(s[i]=='.')continue;
for(int j=i;j<n&&s[j]=='o';j+=k){
s[j]='.';
}
ans++;
}
cout<<ans;
return 0;
}



