A. Rook
打印出象棋车的下一步
using namespace std;
void solve(){
string s;
cin>>s;
char a=s[0];
char b=s[1];
set<string>ans;
for(char i='1';i<='8';i++){
string t="";
t+=a;
t+=i;
ans.insert(t);
}
for(char i='a';i<='h';i++){
string t="";
t=t+i;
t=t+b;
ans.insert(t);
}
for(auto c:ans){
cout<<c<<"\n";
}
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
B. YetnotherrokenKeoard
题意:
思路:用栈来模拟
using namespace std;
void solve(){
string s;
cin>>s;
int n=s.size();
s=" "+s;
vector<int>da;
vector<int>xiao;
vector<int>vis(n+1);
for(int i=1;i<=n;i++){
if(s[i]=='B'&&da.size()){
vis[da.back()]=1;
da.pop_back();
}else if(s[i]=='b'&&xiao.size()){
vis[xiao.back()]=1;
xiao.pop_back();
}else if(s[i]>='a'&&s[i]<='z'){
xiao.push_back(i);
}else{
da.push_back(i);
}
}
for(int i=1;i<=n;i++){
if(!vis[i] && s[i] != 'B' && s[i] != 'b')cout << s[i];
}
cout<<"\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
标签:string,int,void,namespace,Codeforces,char,Div,913
From: https://www.cnblogs.com/yufan1102/p/17889594.html