简单模拟题。
思路:统计小写字母的个数low_letter。
a.如果等于n/2直接输出0,输出原字符串 。
b.如果大于n/2,将low_letter - n/2的小写字母变成大写字母即可,输出low_letter,输出变化后的字符串。
c.如果小于n/2,将low_letter - n/2的大写字母变成小写字母即可,输出low_letter,输出变化后的字符串。
#include <stdio.h>
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
const int maxn = 205;
char str[maxn];
int main(){
int n;
while(~scanf("%d",&n)){
scanf("%s",str);
int len = (int)strlen(str);
int low_letter = 0;
for(int i = 0;i < len;i++){
if(str[i] == 'x')
low_letter++;
}
if(low_letter == n/2){
printf("0\n");
puts(str);
continue;
}
int flag = 0;
if(low_letter > n/2){
low_letter = n - low_letter;
flag = 1;
}
int ans = 0;
if(!flag)
for(int i = 0;i < len;i++){
if(str[i] == 'X'){
str[i] = 'x';
ans++;
}
if(ans >= n/2 - low_letter)
break;
}
else
for(int i = 0;i < len;i++){
if(str[i] == 'x'){
str[i] = 'X';
ans++;
}
if(ans >= n/2 - low_letter)
break;
}
printf("%d\n",ans);
puts(str);
}
return 0;
}