Codeforces Round #242 (Div. 2) A

question:ios

A. Squatsui

time limit per testspa

1 secondcode

memory limit per testip

256 megabytesci

inputget

standard inputinput

outputstring

standard outputit

Pasha has many hamsters and he makes them work out. Today, n hamsters (n is even) came to work out. The hamsters lined up and each hamster either sat down or stood up.

For another exercise, Pasha needs exactly  hamsters to stand up and the other hamsters to sit down. In one minute, Pasha can make some hamster ether sit down or stand up. How many minutes will he need to get what he wants if he acts optimally well?

Input

The first line contains integer n (2 ≤ n ≤ 200n is even). The next line contains n characters without spaces. These characters describe the hamsters' position: the i-th character equals 'X', if the i-th hamster in the row is standing, and 'x', if he is sitting.

Output

In the first line, print a single integer — the minimum required number of minutes. In the second line, print a string that describes the hamsters' position after Pasha makes the required changes. If there are multiple optimal positions, print any of them.

Sample test(s)

input

4
xxXx

output

1
XxXx

input

2
XX

output

1
xX

input

6
xXXxXx

output

0
xXXxXx

ans:

#include <iostream>
#include <algorithm>


using namespace std;

int st; 
int sd;
int n;
int htable[210];

enum {
    NONE,
    SITDOWN,
    STANDUP,
};

int flag;
int cnt;

int main()
{
    cin >> n;
    char a;
    for(int i = 0; i< n; i++){
            cin >> a;
            if('X' == a){
                htable[i] = 1;
                sd++;     
            }else{
                st++;
            }
    }
    flag = NONE;
    cnt = 0;
    if(st > sd){
        flag = STANDUP;
        cnt = st - sd;
    }
    if(st < sd){
        flag = SITDOWN;
        cnt = sd - st;
    }
    cnt >>= 1;
    cout << cnt << endl;;            
    for(int i = 0; i < n; i++){
            if(cnt && (flag == STANDUP ? !htable[i]:htable[i])){
                    cnt--;
                    cout << (flag == STANDUP ? 'X' : 'x');
                    continue;
            }
            cout << (htable[i] ? 'X':'x');
    }
    cout << endl;
    return 0;
}
相關文章
相關標籤/搜索