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. 20、AngularJs知识点总结 part-2

    1.作用域 当你在angularJs中创建控制器时,可以将$scope对象作为一个参数进行传递: scope 是一个 JavaScript 对象,带有属性和方法,这些属性和方法可以在视图和控制器中使用 ...

  2. activiti并发多实例子流程任务处理

    一直在搞工作流(activiti),总结一下关于工作流(activiti)中同时并发处理多个子流程的操作方法. 先说下我要实现的业务: 1.办公室发通知(在系统申报页面上,勾选科室,被选中的科室执行第 ...

  3. ADB连接手机遇到的问题:list of devices attached

    今天工作时想尝试一下使用ADB无线连接手机,结果遇到了下面这样的问题,浪费了几十分钟的时间,挺闹心的,因此想分享出来... 首先 第一步:使用USB数据线连接手机,手机弹出选项时,选择仅充电,然后wi ...

  4. 孤荷凌寒自学python第四十八天通用同一数据库中复制数据表函数最终完成

    孤荷凌寒自学python第四十八天通用同一数据库中复制数据表函数最终完成 (完整学习过程屏幕记录视频地址在文末) 今天继续建构自感觉用起来顺手些的自定义模块和类的代码. 今天经过反复折腾,最终基本上算 ...

  5. 孤荷凌寒自学python第三十四天python的文件操作对file类的对象学习

     孤荷凌寒自学python第三十四天python的文件操作对file类的对象学习 (完整学习过程屏幕记录视频地址在文末,手写笔记在文末) 一.close() 当一个file对象执行此方法时,将关闭当前 ...

  6. CodeSimth - .Net Framework Data Provider 可能没有安装。解决方法[转载 ]

    原文:http://www.cnblogs.com/chenrui7/p/3592082.html 今天想使用CodeSimth生成一个sqlite数据库的模板.当添加添加数据库的时候发现: .Net ...

  7. A - 最长上升子序列

    A - 最长上升子序列 Time Limit: 1000/1000MS (C++/Others) Memory Limit: 65536/65536KB (C++/Others) Problem De ...

  8. SQLAlchemy技术文档(中文版)(中)

    10.建立联系(外键) 是时候考虑怎样映射和查询一个和Users表关联的第二张表了.假设我们系统的用户可以存储任意数量的email地址.我们需要定义一个新表Address与User相关联. from ...

  9. 第十六篇:django基础

    本篇内容 创建程序 程序目录 流程介绍 login实例 一.创建程序 命令行: django-admin startproject sitename. 常用命令: python manage.py r ...

  10. hadoop生态圈列式存储系统--kudu介绍及安装配置

    介绍 Kudu 是一个针对 Apache Hadoop 平台而开发的列式存储管理器.Kudu 共享 Hadoop 生态系统应用的常见技术特性: 它在 commodity hardware(商品硬件)上 ...