FZU-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
3 4
2 5 2
3 6 3 1
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]='\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(字符串,模拟)的更多相关文章
- 用字符串模拟两个大数相加——java实现
问题: 大数相加不能直接使用基本的int类型,因为int可以表示的整数有限,不能满足大数的要求.可以使用字符串来表示大数,模拟大数相加的过程. 思路: 1.反转两个字符串,便于从低位到高位相加和最高位 ...
- HDU-3787(字符串模拟)
Problem Description 给定两个整数A和B,其表示形式是:从个位开始,每三位数用逗号","隔开.现在请计算A+B的结果,并以正常形式输出. Input 输入包含 ...
- HDU-1002.大数相加(字符串模拟)
本题大意:给出两个1000位以内的大数a 和b,让你计算a + b的值. 本题思路:字符串模拟就能过,会Java的大佬应该不会点进来...... 参考代码: #include <cstdio&g ...
- 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 ...
- HDU-Digital Roots(思维+大数字符串模拟)
The digital root of a positive integer is found by summing the digits of the integer. If the resulti ...
- Vigenère密码 2012年NOIP全国联赛提高组(字符串模拟)
P1079 Vigenère 密码 题目描述 16 世纪法国外交家 Blaise de Vigenère 设计了一种多表密码加密算法――Vigenère 密 码.Vigenère 密码的加密解密算法简 ...
- CCF(JSON查询:40分):字符串+模拟
JSON查询 201709-3 纯字符串模拟,考的就是耐心和细心.可惜这两样我都缺... #include<iostream> #include<cstdio> #includ ...
- codeforces 723B Text Document Analysis(字符串模拟,)
题目链接:http://codeforces.com/problemset/problem/723/B 题目大意: 输入n,给出n个字符的字符串,字符串由 英文字母(大小写都包括). 下划线'_' . ...
- 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 ...
随机推荐
- selenium + python之元素定位
selenium对web各元素的操作首先就要先定位元素,定位元素的方法主要有以下几种:通过id定位元素:find_element_by_id("id_vaule")通过name定位 ...
- NodeJs02 美女爬虫
note: demo代码要编号 导出模块 一个js文件就是一个模块,模块内部的所有变量,对象,方法对外界都不可见.如果想暴漏出去让别人用,就需要导出模块.语法如下: module.exports = ...
- SQL 基础笔记(一)
本笔记整理自<SQL 基础教程>.<MySQL 必知必会>和网上资料.个人笔记不保证正确. 一.基础 SQL,即结构化查询语言,是为访问与操作关系数据库中的数据而设计的语言. ...
- HDU 4262 Juggler 树状数组
将每个球按输入顺序编号,建立 它第几个被扔掉->编号 的映射关系. 记录当前在手里的球的编号,按扔掉的顺序查找这个球的编号,看看这个球是逆时针转到手里更近还是顺时针转到手里更近,即当前扔掉球的编 ...
- H5调试
在PC上的调试 问题:需要调试样式,没有数据不方便调试. 方案:本地mock. EG: chrome书签管理器 →将下面代码存书签里,如下图: javascript: void function() ...
- DPDK的代码规范
每个公司都会有自己代码风格或者编程规范,都旨在防范编程语言的一些陷阱或者提高代码效率,还有就是保持一致编码风格来提高代码可读性,方便code review: 或者说代码的一种美学,比如python也就 ...
- 关于jdk与jre的区别
JDK:Java Development Kit JRE顾名思义是java运行时环境,包含了java虚拟机,java基础类库.是使用java语言编写的程序运行所需要的软件环境,是提供给想运行java程 ...
- 如何修改root密码
默认情况下,每次登录ubuntu都会生成一个随机的root密码,如果想要修改, sudo passwd 然后输入密码,这个密码就作为root用户的密码
- thinkPHP判断是否修改成功
thinkPHP中使用save方法来更新数据的save方法的正常执行时返回值是影响的记录数,出错时返回false,返回为0和返回false在很多业务场景下都是不同的. 而当修改的内容和原有内容一致的时 ...
- CSU 2130~湖南多校对抗第八场 C
2130: Permutations Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: ...