C + + question

Source: Internet
Author: User

The set of written test questionquestion1:adjustment Queue
  • In the Kindergarten,there is N children arranged in a team,with one number from left to right (0~n-1). Some of them is Boys,some is girl,boys is represented by ' B ', and girls is indicated by ' G '. The children was very naughty,and when a boy was squattion with a girl,there would 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 is only allow the 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 would make the previous-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

C + + question

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.