Card games
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)
Total Submission (s): 92 Accepted Submission (s): 19
Problem Description
James was bored at home recently, so he invented an interesting game. Game props are N cards stacked together, each card has a number ranging from 0 ~ 9. The game rules are as follows:
First, take the top card and put it on the table. Then, take the top card each time and put it to the rightmost or leftmost of the existing card sequence on the table. When N cards are all placed on the table, N cards on the table constitute a number. This number cannot have a leading 0, that is, the number on the leftmost card cannot be 0. The goal of the game is to minimize this number.
Now your task is to help James write a segment program and find the minimum number.
Input
The first row is a number T, indicating that there are T groups of test data;
Then there are T rows below, each row contains only 0 ~ The string of 9 indicates N cards stacked together, And the leftmost number indicates the top card.
[Technical Specification]
T <= 1000
1 <= N <= 100
Output
For each group of test data, output the minimum number in one row.
Sample Input
3
565
9876543210
9876105432
Sample Output
556
1234567890
1678905432
Source
2013 Jinshan xishanju creative game program challenge-Preliminary Round (2)
Recommend
Liuyiding
Nimei's. I don't understand this question. I did it only after reading someone else's question =!
[Cpp]
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <string>
Using namespace std;
# Define N 1010
Char s [N];
Int main (){
Int T, I, j;
String;
Scanf ("% d", & T );
While (T --){
Scanf ("% s", s );
A = s [0];
Char m = '9 ';
Int j = 0;
For (I = 0; s [I]; I ++ ){
If (s [I]! = '0') {// locate the non-zero minimum number
If (m> = s [I]) m = s [j = I];
}
}
For (I = 1; s [I]; I ++ ){
If (I = j) a = s [I] +;
Else if (I> j ){
A + = s [I];
} Else if (I <j ){
If (s [I]> a [0]) a + = s [I];
Else a = s [I] +;
}
}
Cout <a <endl;
}
Return 0;
}
# Include <iostream>
# Include <cstdio>
# Include <cstring>
# Include <string>
Using namespace std;
# Define N 1010
Char s [N];
Int main (){
Int T, I, j;
String;
Scanf ("% d", & T );
While (T --){
Scanf ("% s", s );
A = s [0];
Char m = '9 ';
Int j = 0;
For (I = 0; s [I]; I ++ ){
If (s [I]! = '0') {// locate the non-zero minimum number
If (m> = s [I]) m = s [j = I];
}
}
For (I = 1; s [I]; I ++ ){
If (I = j) a = s [I] +;
Else if (I> j ){
A + = s [I];
} Else if (I <j ){
If (s [I]> a [0]) a + = s [I];
Else a = s [I] +;
}
}
Cout <a <endl;
}
Return 0;
}