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