Accept: 129 Submit: 865
Time Limit: 1500 mSec Memory Limit : 32768 KB
Problem Description
Fat brother and Maze are playing a kind of special (hentai) game with two integers. All the digits of these two integers are in the range from 1 to 9. After they’ve got these two integers, they thought that these two numbers were not large enough! (You know that the young people always like the HUGE THING in order to have more pleasure) So they decide to use the digits of these two integers to make a new BIGGER integer. At the beginning of this game, the new integer has no digit, each time Fat Brother and Maze can choose one of the two initial integers (if this integer exists) and move its first digit to the end of the new integer. For instance, if the new integer is 233 and the two initial integers are 3154 and 1324 now, they can choose the first digit of the integer 3154, which is 3, and add it to the end of the new integer to make it become 2333. The two initial integers are 154 and 1324 now after this action. Also they can choose the first digit of the integer 1324 and add it to the end of the integer 233 and make it become 2331. This process goes until the two initial integers are all empty. Now Fat Brother and Maze would like to know the maximum number they could get after this special (hentai) game.
Input
The first line of the date is an integer T (1 <= T <= 102), which is the number of the text cases.
Then T cases follow, each case contains two integers N and M (1 <= N,M <= 100000) indicated the number of the digits of these two integers. Then a line with N digits indicates the first integer and a line with M digits indicates the second integer. Note that all the digits are in the range from 1 to 9.
In 90% of test cases, N, M <= 1000.
Output
For each case, output the case number first, and then output the integer Fat Brother and Maze would get, this integer should be as large as possible.
Sample Input
Sample Output
#include<iostream>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#define maxn 200005
using namespace std;
int a[maxn], b[maxn];
int main(){
int n, m;
int t;
int cas = 1;
cin >> t;
while(t--){
scanf("%d%d", &n, &m);
memset(a, 0, sizeof(a)); //这一步必须要有,因为是后面要用到比较函数,那个按照字节比较非常有毒的函数.
memset(b, 0, sizeof(b));
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
}
for(int i = 0; i < m; i++){
scanf("%d", &b[i]);
}
int i = 0, j = 0;
printf("Case %d: ", cas++);
while(i < n && j < m){
if(a[i] > b[j]){
printf("%d", a[i++]);
}
else if(a[i] < b[j])
printf("%d", b[j++]);
else{
int q = memcmp(a+i, b+j, sizeof(a));
if(q < 0){
while(a[i] == b[j] && j < m){
printf("%d", b[j++]);
}
}
else{
while(a[i] == b[j] && i < n){
printf("%d", a[i++]);
}
}
}
}
while(i < n){
printf("%d", a[i++]);
}
while(j < m){
printf("%d", b[j++]);
}
printf("\n");
}
return 0;
}