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