![](http://acm.fzu.edu.cn/image/problem.gif)
Accept: 132 Submit: 935
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
Source
第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)#include<stdio.h> #include<iostream> #include<string> #include<string.h> using namespace std; int a,b; string Q; char A[100001],B[100001]; int main() { int t,n,m,k=1,s=1; scanf("%d",&t); while(t--) { char x,y; Q=""; scanf("%d%d",&n,&m); int ss=0; for(int i=0; i<n; i++) { scanf("%d",&a); A[ss++]=a+'0'; A[ss]=' '; } ss=0; for(int i=0; i<m; i++) { scanf("%d",&b); B[ss++]=b+'0'; B[ss]=' '; } printf("Case %d: ",s++); int j=0,k=0,l=0; while(j<n&&k<m) { x=A[j]; y=B[k]; if(x>y) { j++; Q+=x; } else if(x==y) { int temp=strcmp(A+j,B+k); ///从当前相等的位置开始比较 if(temp>0) { while(j<n && A[j] == B[k]) Q+=A[j++]; } else { while(k<m && A[j] == B[k]) Q+= B[k++]; } } else { k++; Q+=y; } } if(j<n) { for(int i=j; i<n; i++) Q+=A[i]; } if(k<m) { for(int i=k; i<m; i++) Q+=B[i]; } cout<<Q<<endl; } return 0; }