Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u

Submit Status

Description

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 ≤ 200; n 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 Input

Input
4
xxXx
Output
1
XxXx
Input
2
XX
Output
1
xX
Input
6
xXXxXx
Output
0
xXXxXx

Source

题意:一个字符串有n个字符,每个字符不是x就是X,现要求让x和X的个数相等,输出最小的转换次数和转换后的字符串。
题解:统计x和X的个数设为a,b,c=min(a,b),转换最小次数为n/2-a,随便转换几个x或者X然后输出就行了。
#include <iostream>
using namespace std;
int main()
{
int i,n,m,a,b,tmp,ans;
char c[];
while(cin>>n)
{
m=n/;
ans=;
tmp=;
a=;
b=;
for(i=;i<n;i++)
{
cin>>c[i];
if(c[i]=='x')
a++;
else
b++;
}
//cout<<a<<" "<<b<<endl;
if(a<n/)
{
tmp=n/-a;
ans=tmp;
for(i=;i<n;i++)
{
if(tmp==)
break;
if(c[i]=='X')
{
c[i]='x';
tmp--;
}
}
}
else
{
tmp=n/-b;
ans=tmp;
for(i=;i<n;i++)
{
if(tmp==)
break;
if(c[i]=='x')
{
c[i]='X';
tmp--;
}
}
}
cout<<ans<<endl;
for(i=;i<n;i++)
cout<<c[i];
cout<<endl;
} return ;
}

最新文章

  1. c#文本框限制输入内容
  2. IIS安装与MVC程序部署
  3. Ajax本地跨域问题
  4. python的urllib2库详细使用说明
  5. Codeforces Round #354 (Div. 2) D. Theseus and labyrinth
  6. yaf框架流程四
  7. 查看Linux里某文件的前面/后面几行中的某一行
  8. 在 SUSE 11 sp2 上安装 freeradius
  9. VirtualBox虚拟机中启用usb3.0却无法显示u盘的解决方法
  10. 虚拟机显卡分配过高的警告(Insufficient video RAM)
  11. delphi7调用java写的webservice,在调用的时候弹出“wssecurityhandler:request does not contain required security header”
  12. artTemplate模板
  13. Python爬虫——爬豆瓣登录页面
  14. Centos7网络配置-转载
  15. FJUT第四周寒假作业之第一集,临时特工?(深度优先搜索)
  16. 安卓笔记-可以滚动的TextView
  17. Yarn集群的搭建、Yarn的架构和WordCount程序在集群提交方式
  18. 整理Xen理论知识
  19. Linux 查看IP
  20. day 30 客户端获取cmd 命令的步骤

热门文章

  1. groovy-闭包
  2. 栈的的链式实例LinkStack实现
  3. 2层Xml读取类
  4. boost库(条件变量)
  5. 也谈闭包--小白的JS进阶之路
  6. 浏览器的中的 XMLHttpRequest 对象的使用
  7. pthread 学习系列 case1-- 共享进程数据 VS 进程
  8. WPF 检测计算机网络连接情况
  9. 新浪微博客户端(9)-实现版本新特性的ViewPager
  10. linux在安装jdk时报错