Codeforces Round #242 (Div. 2) A. Squats

OpenSoucre發表於2014-04-25

注意題目一次只能改變一個松鼠,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<<"\n"<<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;
    }
}

 

相關文章