1. 程式人生 > >The set of written test question(C++)

The set of written test question(C++)

eas exc you includes minimum not cti osi number

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++)