Blue Bridge cup java questions "shuffling", Blue Bridge java "shuffling"

Source: Internet
Author: User

Blue Bridge cup java questions "shuffling", Blue Bridge java "shuffling"
Problem description: John T plays poker with his roommate in his spare time, And the loser is responsible for shuffling. Although little weak T does not shuffles, he always loses.
Gradually, little weak T found a rule: As Long As You shuffles yourself, you will lose. Therefore, the Small Weak T thinks that the shuffling is not even enough, it creates a small weak shuffling method.
The small and weak shuffling method is used in this way: the traditional shuffling method is used to disrupt 52 playing cards (four cards from 1 to K, excluding the large and small Wang) and put them into a pile, then, each time you get a card from the top of the card stack. If the card size is P (the size from 1 to K is 1 to 13 respectively), insert the card to the back of the P card in the current hand. If the current hand is less than P cards, then put this card at the end.
Now, we will give you a pair of cards that have been disrupted. Please shuffles them with the weak shuffling method and output the final generation sequence.
Note: you may lose some cards when shuffling for the first time. In this case, please Output A-1 to remind you that the number of cards is not enough. The input of the test data in the input format contains N strings separated by spaces to indicate each poker (one of 1 to K) from the top to the bottom of the card stack ). There may be multiple rows. If the output format is N 52, the output sequence is shuffled by the small weak shuffling method. Each string is separated by a space.
Otherwise, output A-1. Example input 4 6 k q 5 1 Q 9 7 9 K 3 J 1 2 3 5
2
3 5 7 Q 7 10 8 4 9 7 8 9 4
10 6 2 8 2 10 10 Q 5 k j 1
J 8 3 K 4 1 6 J 6 sample output 4 1 1 1 1 3 4 6 6 2 2 2 2 5 J 3 8 4 6 k j 8 J 10 10 k q 2 5 7 8 10 9 3 7 9 8 7 1 10 5 6 3 q k q 5 Q 7 9 9 j k data size and conventions ensure that each string is 1 2 3 4 5 6 7 8 9 10 j q k. Code ::

Package Blue Bridge cup java Algorithm training;

Import java. util. Collections list;
Import java. util. List;
Import java. util. collections;

 

Public class _ 4 shuffling {

Public static void main (String [] args ){

Pipeline SC = new pipeline (System. in );

StringBuffer strBuff = new StringBuffer ();

While (SC. hasNext ()){
String s = SC. next ();
// 10 indicates the line feed key.
If (s. equals ("10 ")){
StrBuff. append ("10 ");
} Else {
// 10 line feed, 13 carriage return, 32 Spaces
Char p = s. charAt (0 );
If (! (P = 10 | p = 13 | p = 32 )){
StrBuff. append (char) p) + "");
}
}
}
SC. close ();
String str = strBuff. toString ();
String [] arr = str. split ("");

If (str. length () <52 ){
System. out. println ("-1 ");
} Else {

List <String> list = new partition List <String> ();
For (int I = 0; I <arr. length; I ++ ){
Int index = 0;
If (arr [I]. equals ("J ")){
Index = 11;
} Else if (arr [I]. equals ("Q ")){
Index = 12;
} Else if (arr [I]. equals ("K ")){
Index = 13;
} Else {
Index = Integer. valueOf (arr [I]);
}

If (list. size () <= index ){
List. add (arr [I]);
} Else {
List. add (index, arr [I]);
}
}
For (int I = 0; I <list. size (); I ++ ){
If (I = list. size ()-1 ){
System. out. print (list. get (I ));
} Else {
System. out. print (list. get (I) + "");
}

}
}
}
}

 

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.