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. 【Substring with Concatenation of All Words】cpp

    题目: You are given a string, s, and a list of words, words, that are all of the same length. Find all ...

  2. Spring Boot多数据源配置(一)durid、mysql、jpa整合

    目前在做一个统计项目.需要多数据源整合,其中包括mysql和mongo.本节先讲mysql.durid.jpa与spring-boot的整合. 引入Durid包 <dependency> ...

  3. hnust py road

    问题 C: Py Road 时间限制: 1 Sec  内存限制: 128 MB提交: 125  解决: 34[提交][状态][讨论版] 题目描述 Life is short,you need Pyth ...

  4. Day1 Toast/Menu/Intent传递数据

    ** --------------->未经允许,禁止转载<----------------** 今天是我读<第二行代码>的第一天,也是我第一次开始写CSDN博客,之前的笔记都在 ...

  5. 容器基础(二): 使用Namespace进行边界隔离

    Linux Namespace 容器技术可以认为是一种沙盒(sandbox), 为了实现沙盒/容器/应用间的隔离,就需要一种技术来对容器界定边界,从而让容器不至于互相干扰.当前使用的技术就是Names ...

  6. .NET Core Linux 部署实践

    部署环境:CentOS 7 x64 必要条件:当前用户有sudo权限 1. 安装依赖包sudo yum install libunwind libicu2. 下载.net core安装文件curl - ...

  7. PHP路径相关 dirname,realpath,__FILE__

    ​比如:程序根目录在:E:\wamp\www 中 1.    __FILE__   当前文件的绝对路径 如果在index.php中调用 则返回  E:\wamp\www\index.php 下面再看一 ...

  8. static_cast AND dynamic_cast

    类型转换是一种机制,让程序员能够暂时或永久性改变编译器对对象的解释.注意,这并不意味着程序员改变了对象本身,而只是改变了对对象的解释. 在很多情况下,类型转换是合理的需求,可解决重要的兼容问题.因此, ...

  9. 【转】通过制作Flappy Bird了解Native 2D中的RigidBody2D和Collider

    作者:王选易,出处:http://www.cnblogs.com/neverdie/ 欢迎转载,也请保留这段声明.如果你喜欢这篇文章,请点[推荐].谢谢! 引子 在第一篇文章[Unity3D基础教程] ...

  10. linux perf: 为什么采样频率设置成99Hz而不是100Hz

    早晨在linuxer看到文章,感觉挺有意思,最早研究perf的时候接触过这些概念,乍一看倍感亲切. sudo perf record -F  99 -a -g --sleep 20 perf reco ...