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. poj 3261 二分答案+后缀数组 求至少出现k次的最长重复子序列

    #include "stdio.h" #define maxn 20010 int wa[maxn],wb[maxn],wv[maxn],ws[maxn]; int rank[ma ...

  2. Bzoj1115 石子游戏Kam

    这是道权限题,差评. 题目说明引自ZYF-ZYF Description 有N堆石子,除了第一堆外,每堆石子个数都不少于前一堆的石子个数.两人轮流操作每次操作可以从一堆石子中移走任意多石子,但是要保证 ...

  3. 连通性1 求无向图的low值

    这是DFS系列的第一篇 . 首先给出一个重要的定理.该定理来自<算法导论>. An undirected graph may entail some ambiguity in how we ...

  4. window自动切换ip的脚本

    因为总要切换ip,所以百度了一下脚本 如下http://jingyan.baidu.com/article/d2b1d1029d21b95c7e37d4fa.html 动态ip netsh inter ...

  5. UVA1262Password(第K字典序)

    题目链接 紫书P323 题意:两个6*5的字母矩阵,两个矩阵每列相同的字母,每列取一个,求按照字典序第k小的序列 分析: 对于第一个样例来说,我们得到{ACDW}.{BOP}.{GMOX}.{AP}. ...

  6. ecmall模板语法

    ECMall的模板解析语法介绍 用"{"开头,以"}"结尾就构成一个标签单元 在 2011年07月19日 那天写的     已经有 19105 次阅读了 感谢  ...

  7. 锋利的jQuery-4--阻止事件冒泡和阻止默认行为

    阻止事件冒泡: 如果嵌套元素分别有自己的click事件,当点击内层元素时外层元素的事件也会被触发. $("span").bind("click", functi ...

  8. URLDecoder与URLEncoder

    网页中的表单使用POST方法提交时,数据内容的类型是 application/x-www-form-urlencoded,这种类型会: 1.字符"a"-"z", ...

  9. Caused by: java.lang.NoSuchFieldError: TRACE

    Caused by: java.lang.NoSuchFieldError: TRACE at org.slf4j.impl.Log4jLoggerAdapter.trace(Log4jLoggerA ...

  10. 在Microsoft-IIS/10.0上面部署mvc站点的时候,出现404的错误

    写在前面 在家自己弄了一个项目,想部署在电脑上用手机来访问,总是出现404的错误.路由什么的没有写错啊,最后发现是映射程序的问题,在安装的时候iis很多功能没有安装,又将iis的其他没有安装的功能勾选 ...