首页 > 其他 > 详细

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

时间:2014-04-26 07:29:24      阅读:486      评论:0      收藏:0      [点我收藏+]

注意题目一次只能改变一个松鼠,Pasha can make some hamster ether sit down or stand up.是单数不是复数

bubuko.com,布布扣
#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;
    }
}
bubuko.com,布布扣

 

Codeforces Round #242 (Div. 2) A. Squats,布布扣,bubuko.com

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

原文:http://www.cnblogs.com/xiongqiangcs/p/3689366.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!