码迷,mamicode.com
首页 > 编程语言 > 详细

The set of written test question(C++)

时间:2018-07-21 19:52:13      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:des   put   written   pre   ict   rev   you   string   dict   

The set of written test question

Question1:Adjustment Queue

  • In the kindergarten,there are n children arranged in a team,with one number from left to right(0~n-1).Some of them are boys,some are girl,boys are represented by ‘B‘,and girls are indicated by ‘G‘.The children are very naughty,and when a boy is squattion with a girl,there will be contradiction.As a kindergarten teacher,you need to let the boys take the girls or girls to the least.You cna only make adjustmentson the original formation.Each adjustment can only allow the two adjacent childrento exchange positions.Now you need to complete the team adjustment as soon as possible.You need to calculate the minimum number of adjustments you need to make the situation the least.For example:GGBBG->GGBGB->GGGBB
    This will make the previous two male and female neighbors become adjacent,and need to adjust the formation 2 times.
    Enter a description:
    The input data includes a string of length n and containing only G and B.n does not exceed 50.
    Output description:
    Output an integer indicating the minimum number of adjustments required for the team.
    Input example:
    Output example:
    2

The set of written test question(C++)

标签:des   put   written   pre   ict   rev   you   string   dict   

原文地址:https://www.cnblogs.com/hugeng007/p/9347657.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!