HDUOJ---------Kia's Calculation
Kia's Calculation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 624 Accepted Submission(s): 178
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define maxn 1000000 //1e6
using namespace std;
char a[maxn+5],b[maxn+5],c[maxn+5];
void cal(int *str,char *a,int len)
{
for(int i=0;i<len;i++)
{
str[a[i]-'0']++;
}
}
int main()
{
int t,i,j,count=1,max,posi,posj,len1,k;
//freopen("test.in","r",stdin);
//freopen("test.out","w",stdout);
scanf("%d",&t);
while(t--)
{
int A[10]={0},B[10]={0},flag=0;
memset(a,'\0',sizeof a);
memset(b,'\0',sizeof b);
memset(c,'\0',sizeof c);
scanf("%s%s",a,b);
len1=strlen(a);
cal(A,a,len1);
cal(B,b,len1);
printf("Case #%d: ",count++);
for(k=1;k<=len1;k++)
{
max=-1;
for(i=9;i>=0;i--)
{
if(k==1&&i==0&&len1!=1) continue;
if(A[i])
{
for(j=9;j>=0;j--)
{
if(k==1&&j==0&&len1!=1) continue;
if(B[j])
{
int temp=(i+j)%10;
if(max<temp)
{
max=temp;
posi=i;
posj=j;
}
}
if(max==9)break;
}
}
if(max==9)break;
}
A[posi]--;
B[posj]--;
c[flag++]=max+'0';
}
if(flag>1)
{
if(c[0]>'0')
printf("%c",c[0]);
for(i=1;i<flag;i++)
{
printf("%c",c[i]);
if(c[0]<='0'&&c[i]=='0') break;
}
puts("");
}
else
printf("%c\n",c[0]);
}
return 0;
}
HDUOJ---------Kia's Calculation的更多相关文章
- 贪心 HDOJ 4726 Kia's Calculation
题目传送门 /* 这题交给队友做,做了一个多小时,全排列,RE数组越界,赛后发现读题读错了,囧! 贪心:先确定最高位的数字,然后用贪心的方法,越高位数字越大 注意:1. Both A and B wi ...
- HDU 4726 Kia's Calculation (贪心算法)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...
- Kia's Calculation hdu4726
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- K - Kia's Calculation (贪心)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 4726 Kia's Calculation(贪心)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- K - Kia's Calculation(贪心)
Kia's Calculation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Kia's Calculation(HDU 4267)
Problem Description Doctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is ...
- ACM学习历程—HDU 4726 Kia's Calculation( 贪心&&计数排序)
DescriptionDoctor Ghee is teaching Kia how to calculate the sum of two integers. But Kia is so carel ...
- hdu 4726 Kia's Calculation
思路:刚开始想复杂了. 看解题报告后才知道这题挺简单的,看来还是要多训练啊!!! 单独处理首位的数字,不能为0.其他的就好处理了,从大到小依次找下去就可以了…… 代码如下: #include<i ...
- HDU 4726 Kia's Calculation(贪心构造)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4726 题意:给出两个n位的数字,均无前缀0.重新排列两个数字中的各个数,重新排列后也无前缀0.得到的两 ...
随机推荐
- 如何查看openshift Router的metrics
先找到用户名和密码 [root@master ~]# oc describe pod router--8pjrb | grep STATS_ STATS_PASSWORD: mFj58DpaOQ ST ...
- 初识Tomcat
Tomcat的安装非常简单,解压即可! Tomcat要正常运行,需要配置一个环境变量JAVA_HOME,指向jdk的主目录.
- Longest Substring Without Repeating Characters leetcode java
题目: Given a string, find the length of the longest substring without repeating characters. For examp ...
- iphone手机微信端html5 Geolocation定位失效的问题
使用Geolocation方法存在错误信息error.POSITION_UNAVAILABLE 其实问题不局限于微信端而是iphone升级到ios10后,对获取地理位置信息作出了限制,只有https的 ...
- _com_util::ConvertBSTRToString的使用问题
#include <comutil.h> 然后调用_com_util::ConvertBSTRToString提示如下错误: error LNK2019: unresolved exter ...
- Java 之 Given final block not properly padded
获取Cipher对象的时候一定要写成 Cipher cipher = Cipher.getInstance("DES/ECB/NoPadding"); 不要写成 Cipher ci ...
- SqlServer日常积累(一)
1. 将一个表的数据插入另一个表 情况一:目标表已存在 (1)如果2张表的字段一致,并且希望插入全部数据,可以用这种方法: Insert Into 目标表 Select * From 来源表; --例 ...
- Android 之 AndroidManifest.xml 详解(一)
当Android启动一个应用程序组件之前,它必须知道哪些个组件是存在的,所以开发人员在开发过程中,必须将应用程序中出现的组件一一在AndroidManifest.xml文件中" 声明 &qu ...
- 腾讯云兑现存储获取临时授权C#版
腾讯官方没有提供C#版的,没办法自己根据java版改写了一个,这里面的坑花了我20多个小时,所以记录下 <%@ WebHandler Language="C#" Class= ...
- cat 命令(转)
原文:http://www.cnblogs.com/peida/archive/2012/10/30/2746968.html cat命令的用途是连接文件或标准输入并打印.这个命令常用来显示文件内容, ...