Kia's Calculation

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1367    Accepted Submission(s): 327

Problem Description
Doctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so careless and alway forget to carry a number when the sum of two digits exceeds 9. For example, when she calculates 4567+5789, she will get 9246, and for 1234+9876, she will get 0. Ghee is angry about this, and makes a hard problem for her to solve:
Now Kia has two integers A and B, she can shuffle the digits in each number as she like, but leading zeros are not allowed. That is to say, for A = 11024, she can rearrange the number as 10124, or 41102, or many other, but 02411 is not allowed.
After she shuffles A and B, she will add them together, in her own way. And what will be the maximum possible sum of A "+" B ?
 
Input
The rst line has a number T (T <= 25) , indicating the number of test cases.
For each test case there are two lines. First line has the number A, and the second line has the number B.
Both A and B will have same number of digits, which is no larger than 106, and without leading zeros.
 
Output
For test case X, output "Case #X: " first, then output the maximum possible sum without leading zeros.
 
Sample Input
1
5958
3036
 
Sample Output
Case #1: 8984
 #include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
int a[],b[];
int fun()
{
int i,j,k;
for(k=; k>=; k--)
{
for(i=; i>=; i--)
{
for(j=; j>=; j--)
{
if(a[i]&&b[j]&&(i+j)%==k)
{
a[i]--,b[j]--;
printf("%d",k);
return k;
}
}
}
}
}
int main()
{
int t,i,j,k,r;
char x;
scanf("%d",&t);
getchar();
for(r=; r<=t; r++)
{
memset(a,,sizeof(a));
memset(b,,sizeof(b));
while(x=getchar())
{
if(x=='\n')break;
a[x-'']++;
}
while(x=getchar())
{
if(x=='\n')break;
b[x-'']++;
}
printf("Case #%d: ",r);
if(fun())
for(k=; k>=; k--)
{
for(i=; i>=; i--)
{
for(j=; j>=; j--)
{
while(a[i]&&b[j]&&(i+j)%==k)
{
a[i]--,b[j]--;
printf("%d",k);
}
}
}
}
puts("");
}
}
 

Kia's Calculation hdu4726的更多相关文章

  1. 贪心 HDOJ 4726 Kia's Calculation

    题目传送门 /* 这题交给队友做,做了一个多小时,全排列,RE数组越界,赛后发现读题读错了,囧! 贪心:先确定最高位的数字,然后用贪心的方法,越高位数字越大 注意:1. Both A and B wi ...

  2. HDU 4726 Kia's Calculation (贪心算法)

    Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...

  3. K - Kia's Calculation (贪心)

    Kia's Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  4. HDU 4726 Kia's Calculation(贪心)

    Kia's Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. K - Kia's Calculation(贪心)

    Kia's Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. HDU-4726 Kia's Calculation 贪心

    题目链接:http://acm.hdu.edu.cn/userstatus.php?user=zhsl 题意:给两个大数,他们之间的加法法则每位相加不进位.现在可以对两个大数的每位重新排序,但是首位不 ...

  7. HDU4726——Kia's Calculation——2013 ACM/ICPC Asia Regional Online —— Warmup2

    题目的意思是给你两个数字(多达10^6位) 做加法,但是有一点,没有进位(进位不算,相当于这一位相加后对10取模) 你可以任意排列两个数字中的每一位,但是不能是0开头. 现在题目要求以这种不进位的算法 ...

  8. Kia's Calculation(HDU 4267)

    Problem Description Doctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is ...

  9. ACM学习历程—HDU 4726 Kia's Calculation( 贪心&&计数排序)

    DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so carel ...

随机推荐

  1. edittext基本用法总结.md

    光标的有关问题 edittext.setSelection(2); //记住一个不能越界的bug edittext.setCursorVisible(false); //设置光标显示,不能设置光标颜色 ...

  2. kettle表输入条件参数设置

    @ 获取系统信息:设置命令参数 @ 表输入:

  3. css控制竖直文字显示

    假如有一天,你把水平文字看腻味了...... 我建议你不妨试试垂直文字显示,就像这样: 我 是 竖 直 显 示 的 : 哈哈! 言归正传,怎么把一段话,垂直显示呢? 方法1: //把下面代码另存为ht ...

  4. Tornado框架简介

    -------------------简介------------------- 1.概念:     Tornado全称Tornado Web Server,是一个用Python语言写成的Web服务器 ...

  5. 插入排序与希尔排序Java实现

    public class TestMain { public static void main(String[] args) { Integer[] a = new Integer[5000]; fo ...

  6. [js高手之路]深入浅出webpack教程系列4-插件使用之html-webpack-plugin配置(上)

    还记得我们上文中的index.html文件吗? 那里面的script标签还是写死的index.bundle.js文件,那么怎么把他们变成动态的index.html文件,这个动态生成的index.htm ...

  7. Java泛型:泛型类,泛型接口和泛型方法

    转自: https://segmentfault.com/a/1190000002646193 泛型的产生很多缘由是因为 容器类  的创建 泛型类 容器类应该算得上最具重用性的类库之一.先来看一个没有 ...

  8. docker+tomcat 启动时非常慢原因之JRE /dev/random阻塞

    docker+tomcat 启动时非常慢,一般正常启动几十秒的,发现docker+tomcat启动竟需要几分钟,不可思议 根本原因是 SecureRandom 这个 jre 的工具类的问题.那为什么 ...

  9. 使用sql语句复制一张表

    如何使用sql语句复制一张表? 方法一:第一步:先建一张新表,新表的结构与老表相等. create table newbiao like chengjibiao(老表名); 第二步:将老表中的值复制到 ...

  10. 防止fixed元素遮挡其他元素的方法

    有多个页面,有的有固定的头部(设置了postion:fixed的元素),有的没有固定的头部,这时就有个问题,有固定头部的页面,头部会遮挡下面的内容,那怎么解决呢? <!DOCTYPE html& ...