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
-
1 Importjava.util.Arrays;2 ImportJava.util.Scanner;3 4 Public classMain {5 Public Static voidMain (string[] args) {6Scanner scanner=NewScanner (system.in);7 intT;8 Charschar[];9 inti;Ten intR; One intW; A intB; - -t=scanner.nextint (); the while(true){ - if(t==0) - Break; -t--; + -Schar=Scanner.next (). ToCharArray (); + AR=0; atW=0; -B=0; - for(i=0;i<schar.length;i++){ - if(schar[i]== ' R ') -r++; - Else if(schar[i]== ' W ') inw++; - Else tob++; + } - the for(i=0;i<r;i++) *System.out.print ("R"); $ Panax Notoginseng for(i=0;i<w;i++) -System.out.print ("W"); the + for(i=0;i<b;i++) ASystem.out.print ("B"); the + System.out.println (); - } $ } $}
Question of the Dutch flag