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 ;
}

Codeforces 424A (思维题)的更多相关文章

  1. Vova and Trophies CodeForces - 1082B(思维题)

    Vova has won nn trophies in different competitions. Each trophy is either golden or silver. The trop ...

  2. CodeForces - 417B (思维题)

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

  3. CodeForces - 417A(思维题)

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

  4. B - Sonya and Exhibition CodeForces - 1004B (思维题)

    B. Sonya and Exhibition time limit per test 1 second memory limit per test 256 megabytes input stand ...

  5. codeforces ~ 1009 B Minimum Ternary String(超级恶心的思维题

    http://codeforces.com/problemset/problem/1009/B B. Minimum Ternary String time limit per test 1 seco ...

  6. 贪心/思维题 Codeforces Round #310 (Div. 2) C. Case of Matryoshkas

    题目传送门 /* 题意:套娃娃,可以套一个单独的娃娃,或者把最后面的娃娃取出,最后使得0-1-2-...-(n-1),问最少要几步 贪心/思维题:娃娃的状态:取出+套上(2),套上(1), 已套上(0 ...

  7. C. Nice Garland Codeforces Round #535 (Div. 3) 思维题

    C. Nice Garland time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  8. CodeForces - 631C ——(思维题)

    Each month Blake gets the report containing main economic indicators of the company "Blake Tech ...

  9. CodeForces - 1102A(思维题)

    https://vjudge.net/problem/2135388/origin Describe You are given an integer sequence 1,2,-,n. You ha ...

随机推荐

  1. web.xml中/与/*的区别

    1.拦截"/",可以实现现在很流行的REST风格.很多互联网类型的应用很喜欢这种风格的URL.为了实现REST风格,拦截了所有的请求.同时对*.js,*.jpg等静态文件的访问也就 ...

  2. OpenJudge 7627 鸡蛋的硬度

    描述 最近XX公司举办了一个奇怪的比赛:鸡蛋硬度之王争霸赛.参赛者是来自世 界各地的母鸡,比赛的内容是看谁下的蛋最硬,更奇怪的是XX公司并不使用什么精密仪器来测量蛋的硬度,他们采用了一种最老土的办法- ...

  3. Recon-Erlang线上系统诊断工具

    Erlang系统素以稳定可靠闻名,但是它也是c实现的,也是要管理比如内存,锁等等复杂的事情,也会出现Crash,而且crash的时候大部分原因是因为内存问题.为此erlang运行期提供了强大的自省机制 ...

  4. hihocoder #1058 Combination Lock

    传送门 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Finally, you come to the interview room. You know that a ...

  5. Mongo报如下类似错误时的修改方法Cannot natively represent the long 1396367483000 on this platform

    今天通过php连接mongodb,并读取数据时,其中一个字段为: "createTime":NumberLong("1397524645000"),由于太长,一 ...

  6. javascript学习随笔(二)原型prototype

    JavaScript三类方法: 1.类方法:2.对象方法:3.原型方法;注意三者异同 例: function People(name){ this.name=name; //对象方法 this.Int ...

  7. pthread clean up

    https://www.ibm.com/developerworks/cn/linux/thread/posix_threadapi/part4/ http://www.cnblogs.com/xfi ...

  8. Linux下安装php screw

    1.下载地址:http://sourceforge.net/projects/php-screw/ 2. tar zxvf php_screw_1.5.tar.gz cd php_screw_1.5 ...

  9. linux c程序中获取shell脚本输出的实现方法

    linux c程序中获取shell脚本输出的实现方法 1. 前言Unix界有一句名言:“一行shell脚本胜过万行C程序”,虽然这句话有些夸张,但不可否认的是,借助脚本确实能够极大的简化一些编程工作. ...

  10. Windows下文件的所有和权限

    跟linux不同, 在linux下 ,文件的所有者,就拥有对文件的所有读写执行的权限, 而windows, 文件的所有者不一定对文件拥有所有的权限, 场景: 要对系统文件(windows\system ...