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
  1. 4
    xxXx
Output
  1. 1
    XxXx
Input
  1. 2
    XX
Output
  1. 1
    xX
Input
  1. 6
    xXXxXx
Output
  1. 0
    xXXxXx

Source

题意:一个字符串有n个字符,每个字符不是x就是X,现要求让x和X的个数相等,输出最小的转换次数和转换后的字符串。
题解:统计x和X的个数设为a,b,c=min(a,b),转换最小次数为n/2-a,随便转换几个x或者X然后输出就行了。
  1. #include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int i,n,m,a,b,tmp,ans;
  6. char c[];
  7. while(cin>>n)
  8. {
  9. m=n/;
  10. ans=;
  11. tmp=;
  12. a=;
  13. b=;
  14. for(i=;i<n;i++)
  15. {
  16. cin>>c[i];
  17. if(c[i]=='x')
  18. a++;
  19. else
  20. b++;
  21. }
  22. //cout<<a<<" "<<b<<endl;
  23. if(a<n/)
  24. {
  25. tmp=n/-a;
  26. ans=tmp;
  27. for(i=;i<n;i++)
  28. {
  29. if(tmp==)
  30. break;
  31. if(c[i]=='X')
  32. {
  33. c[i]='x';
  34. tmp--;
  35. }
  36. }
  37. }
  38. else
  39. {
  40. tmp=n/-b;
  41. ans=tmp;
  42. for(i=;i<n;i++)
  43. {
  44. if(tmp==)
  45. break;
  46. if(c[i]=='x')
  47. {
  48. c[i]='X';
  49. tmp--;
  50. }
  51. }
  52. }
  53. cout<<ans<<endl;
  54. for(i=;i<n;i++)
  55. cout<<c[i];
  56. cout<<endl;
  57. }
  58.  
  59. return ;
  60. }

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. BZOJ-1207 打鼹鼠 DP(LIS)

    1207: [HNOI2004]打鼹鼠 Time Limit: 10 Sec Memory Limit: 162 MB Submit: 2276 Solved: 1116 [Submit][Statu ...

  2. 网络包处理工具NetBee

    What is NetBee? NetBee is a new library intended for several types of packet processing, such as pac ...

  3. slf4j和log4j配置

    SLF4J即简单日志门面(Simple Logging Facade for Java),不是具体的日志解决方案,它只服务于各种各样的日志系统.按照官方的说法,SLF4J是一个用于日志系统的简单Fac ...

  4. appium-向右滑动定位

    上面5幅欢迎图,要向右滑动4次再点击[立即体验]才可以到首屏 #首页欢迎图滑动4次 for i in range(4): driver.swipe(1200, 200, 10, 200, 1500) ...

  5. ActivityInfo taskAffinity

    通常在Manifest里面使用 <application android:icon="@drawable/icon" android:label="@string/ ...

  6. electron加载jquery报错问题

    <!-- Insert this line above script imports --> <script>if (typeof module === 'object') { ...

  7. 可以开心的用Markdown了

    1 计划 月计划 周计划 日计划 2 实现

  8. Sphinx学习之sphinx的安装篇

    一.  Sphinx简介 Sphinx是由俄罗斯人Andrew Aksyonoff开发的一个全文检索引擎.意图为其他应用提供高速.低空间占用.高结果 相关度的全文搜索功能.Sphinx可以非常容易的与 ...

  9. Initialization of deep networks

    Initialization of deep networks 24 Feb 2015Gustav Larsson As we all know, the solution to a non-conv ...

  10. GDB中应该知道的几个调试方法 来自陈皓

    GDB中应该知道的几个调试方法 2011年2月10日陈皓发表评论阅读评论62,325 人阅读   七.八年前写过一篇<用GDB调试程序>,于是,从那以后,很多朋友在MSN上以及给我发邮件询 ...