Problem 2267 The Bigger the Better

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

1
3 4
2 5 2
3 6 3 1

 Sample Output

Case 1: 3632521

 Source

第七届福建省大学生程序设计竞赛-重现赛(感谢承办方闽江学院)

思路:字符串处理用strcmp函数
代码:
#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]='\0';
}
ss=0;
for(int i=0; i<m; i++)
{
scanf("%d",&b);
B[ss++]=b+'0';
B[ss]='\0';
}
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;
}

  

 

FZU-2267 The Bigger the Better(字符串,模拟)的更多相关文章

  1. 用字符串模拟两个大数相加——java实现

    问题: 大数相加不能直接使用基本的int类型,因为int可以表示的整数有限,不能满足大数的要求.可以使用字符串来表示大数,模拟大数相加的过程. 思路: 1.反转两个字符串,便于从低位到高位相加和最高位 ...

  2. HDU-3787(字符串模拟)

    Problem Description 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开.现在请计算A+B的结果,并以正常形式输出.   Input 输入包含 ...

  3. HDU-1002.大数相加(字符串模拟)

    本题大意:给出两个1000位以内的大数a 和b,让你计算a + b的值. 本题思路:字符串模拟就能过,会Java的大佬应该不会点进来...... 参考代码: #include <cstdio&g ...

  4. Codeforces Round #425 (Div. 2) B. Petya and Exam(字符串模拟 水)

    题目链接:http://codeforces.com/contest/832/problem/B B. Petya and Exam time limit per test 2 seconds mem ...

  5. HDU-Digital Roots(思维+大数字符串模拟)

    The digital root of a positive integer is found by summing the digits of the integer. If the resulti ...

  6. Vigenère密码 2012年NOIP全国联赛提高组(字符串模拟)

    P1079 Vigenère 密码 题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简 ...

  7. CCF(JSON查询:40分):字符串+模拟

    JSON查询 201709-3 纯字符串模拟,考的就是耐心和细心.可惜这两样我都缺... #include<iostream> #include<cstdio> #includ ...

  8. codeforces 723B Text Document Analysis(字符串模拟,)

    题目链接:http://codeforces.com/problemset/problem/723/B 题目大意: 输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括). 下划线'_' . ...

  9. Codeforces 1090B - LaTeX Expert - [字符串模拟][2018-2019 Russia Open High School Programming Contest Problem B]

    题目链接:https://codeforces.com/contest/1090/problem/B Examplesstandard input The most famous characters ...

随机推荐

  1. [译]11-spring bean定义的继承

    spring中bean的定义包含很多信息,如,构造器参数.property指定的依赖项.初始化方法.工厂类和工厂方法等. 如果spring容器的中每个bean都重复声明这些属性,是非常烦人也是十分低效 ...

  2. ASP.Net MVC+EF架构

    ASP.Net MVC是UI层的框架,EF是数据访问的逻辑. 如果在Controller中using DbContext,把查询的结果的对象放到cshtml中显示,那么一旦在cshtml中访问关联属性 ...

  3. Nova 如何统计 OpenStack 资源

    1.云计算的本质在于将硬件资源软件化,以达到快速按需交付的效果,最基本的计算.存储和网络基础元素并没有因此改变.就计算而言,CPU.RAM 和 DISK等依旧是必不可少的核心资源. 从源代码和数据库相 ...

  4. 一个符号冲突导致的core分析

    问题描述: 修改跟踪程序(Trace)支持IPV6时,发现程序启动后正常,但是客户端一旦下发查询条件进行跟踪,Trace程序就直接coredump! (gdb) bt # 0x00007f7dab9e ...

  5. C# MemoryCache 类[转载]

    原网址:http://www.cmono.net/post/read/156 MemoryCache 类是.Net .0推出的类库,主要是为了方便在Winform和Wpf中构建缓存框架的 Object ...

  6. POJ3345 Bribing FIPA 【背包类树形dp】

    题目链接 POJ 题解 背包树形dp板题 就是读入有点无聊,浪费了很多青春 #include<iostream> #include<cstdio> #include<cm ...

  7. hibernate用注解的方式实现orm

    hibernate 有两种方式实现把一张表映射成一个对象,一种是配置文件的方式,一种是注解的方式.这里用hibernate提供的注解的方式实现一个对象和一张表之间的对应. 思路: 首先在hiberna ...

  8. Python之多线程:Threading模块

    1.Threading模块提供的类 Thread,Lock,Rlock,Condition,Semaphore,Event,Timer,local 2.threading模块提供的常用的方法 (1)t ...

  9. Windows域同步检查repadmin

    C:\Users\>repadmin /show replUsage: repadmin <cmd> <args> [/u:{domain\user}] [/pw:{pa ...

  10. Pandas之DataFrame——Part 1

    ''' [课程2.] Pandas数据结构Dataframe:基本概念及创建 "二维数组"Dataframe:是一个表格型的数据结构,包含一组有序的列,其列的值类型可以是数值.字符 ...