注意题目一次只能改变一个松鼠,Pasha can make some hamster ether sit down or stand up.是单数不是复数
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main(){ int n; cin >> n; string str; cin >> str; int num = count(str.begin(),str.end(),'X') -n/2; if(num == 0) cout<<0<<" "<<str<<endl; else{ cout<<abs(num)<<endl; int cnt = 0; for(int i = 0 ;i < n && cnt<abs(num); ++ i){ if(num > 0 && str[i]=='X'){ str[i]='x'; cnt++; } if(num < 0 && str[i]=='x'){ str[i]='X'; cnt++; } } cout<<str<<endl; } }