nyoj-Dutch flag issue

Source: Internet
Author: User

Dutch flag issue time limit: theMs | Memory Limit:65535KB Difficulty:1
Describe
The Dutch flag has three horizontal bars, from top to bottom three blocks of color are red, white, and blue in turn. There are several ribbon sequences of red, white, and blue, which you want to rearrange so that all the same colors are striped together. This issue requires that all red bars be placed on the far left, all white bars in the middle, and all the blue bars on the far right.
Input
Line 1th is a positive integer n (n<100), which indicates that there are n sets of test data. Then there are n rows, each with several string sequences of r,w,b three characters, where R,w and b represent the bars of the red, white, and blue colors, and each line has a maximum of 1000 characters.
Output
A
sequence of strings consisting of r,w,b three characters on each line of the input, rearranging them so that all the same colors are striped together to meet the aforementioned requirements.
Sample input
 
 
Sample output
 
 
Source

ACM Textbook

#include <stdio.h> #include <string.h>int main () {int N,i;char str[1010];scanf ("%d", &n), while (n--) { scanf ("%s", str), int len = strlen (str), b,r,w;r=b=w=0;for (i=0;i<len;++i) {if (str[i]== ' B ') b++;else if (str[i]== ' R ') r ++;elsew++;} while (r--) printf ("R"), while (w--) printf ("W"), while (b--) printf ("B");p rintf ("\ n");} return 0;}


nyoj-Dutch flag issue

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.