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. CodeReview Learning

    目录 . 引言 . 代码检视的指导思想 . 代码检视的内容 . 回归测试 0. 引言 代码检视(Code Review)是指软件开发人员在完成代码设计.编写.调试后展开的个人或群体性的代码阅读过程,代 ...

  2. jsp学习(五)

    在进行jsp与jdbc连接时,出现这样一个错误,提示如下: java.net.ConnectException: Connection refused: connect 后来发现是由于mysql数据库 ...

  3. android studio中the logging tag can be most 23 characters

    转:http://blog.csdn.net/voiceofnet/article/details/49866047 今天写代码的时候,突然发现平时用的好好的Log竟然报错,提示信息为:the log ...

  4. groovy-语句

    groovy语句类似于java语句,但是在groovy中的分号”;”是可选的.比如: 1 def x = [1, 2, 3] 2 println x 3 def y = 5; def x = y +  ...

  5. c链表实现遇到的错误

    想完成一个链表发现有错误,代码如下: //http://ac.jobdu.com/problem.php?pid=1511 //֮ǰÓÃlistʵÏֵ쬽ñÌìÊÔÒ»ÏÂÓÃstruct ...

  6. 通过HTTP协议实现多线程下载

    1. 基本原理,每条线程从文件不同的位置开始下载,最后合并出完整的数据. 2. 使用多线程下载的好处     下载速度快.为什么呢?很好理解,以往我是一条线程在服务器上下载.也就是说,对应在服务器上, ...

  7. Mac OS X 10.9 Mavericks安装后,Xcode调试时模拟器黑屏的处理方法

    请耐心的等下去吧,少年! 装了Mac OS X 10.9 Mavericks的同学,如果碰到Xcode调试App时,模拟器黑屏(重置也无效),请耐心的等下去吧,大约10来分钟左右黑屏就会消失,App启 ...

  8. UVA11584 划分成回文串

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/B 紫书275 题意:输入一个字符,最少能划分几个回文串 分析 ...

  9. 牛顿迭代法求n方根

    一.简单推导 二.使用 借助上述公式,理论上可以求任意次方根,假设要求a(假设非负)的n次方根,则有xn=a,令f(x)=xn-a,则只需求f(x)=0时x的值即可.由上述简单推导知,当f(x)=0时 ...

  10. 如何起草你的第一篇科研论文——应该做&避免做

    如何起草你的第一篇科研论文——应该做&避免做 导语:1.本文是由Angel Borja博士所写.本文的原文链接在这里.感谢励德爱思唯尔科技的转载,和刘成林老师的转发.2.由于我第二次翻译,囿于 ...