Bob and math problem

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

Problem Description
Recently, Bob has been thinking about a math problem.
There are N Digits, each digit is between 0 and 9. You need to use this N Digits to constitute an Integer.
This Integer needs to satisfy the following conditions:

    • 1. must be an odd Integer.
    • 2. there is no leading zero.
  • 3. find the biggest one which is satisfied 1, 2.

Example:
There are three Digits: 0, 1, 3. It can constitute six number of
Integers. Only "301", "103" is legal, while "130", "310", "013", "031"
is illegal. The biggest one of odd Integer is "301".

 
Input
There are multiple test cases. Please process till EOF.
Each case starts with a line containing an integer N ( 1 <= N <= 100 ).
The second line contains N Digits which indicate the digit a1,a2,a3,⋯,an.(0≤ai≤9).
 
Output
The
output of each test case of a line. If you can constitute an Integer
which is satisfied above conditions, please output the biggest one.
Otherwise, output "-1" instead.
 
Sample Input
3
0 1 3
3
5 4 2
3
2 4 6
 
Sample Output
301
425
-1
 
Source
 
n个数字组成一个数,问能够组成的最大的奇数是多少?不能有前导0
直接模拟:1,如果全是偶数直接输出-1
       2,从大到小排序,最低位为奇数直接输出,最低位为偶数的话往前挪,找到第一个奇数,注意一下前导0的情况即可。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
int cmp(int a,int b)
{
return a>b;
}
int main()
{
int n,a[];
char c[];
while(scanf("%d",&n)!=EOF)
{
bool flag = false;
for(int i=; i<=n; i++)
{
scanf("%d",&a[i]);
if(a[i]%==) flag = true;
}
if(!flag) printf("-1\n");
else
{
int res[];
sort(a+,a+n+,cmp);
if(a[n]%==)
{
for(int i=; i<=n; i++)
{
res[i] = a[i];
}
}
else
{
int t = n;
for(int i=n; i>=; i--)
{
if(a[i]%==)
{
t = a[i];
a[i] = -;
break;
}
}
int cnt=;
for(int i=; i<=n; i++)
{
if(a[i]==-) continue;
res[cnt++] = a[i];
}
res[cnt] = t;
}
if(res[]==) printf("-1\n");
else
{
for(int i=; i<=n; i++)
{
printf("%d",res[i]);
}
printf("\n");
}
}
}
return ;
}

hdu 5055(模拟)的更多相关文章

  1. hdu 5055

    http://acm.hdu.edu.cn/showproblem.php?pid=5055 n个digit能组合出的最大无前导0奇数 无聊的模拟 #include <cstdio> #i ...

  2. HDU 5055 Bob and math problem(简单贪心)

    http://acm.hdu.edu.cn/showproblem.php?pid=5055 题目大意: 给你N位数,每位数是0~9之间.你把这N位数构成一个整数. 要求: 1.必须是奇数 2.整数的 ...

  3. HDU 5055 Bob and math problem(结构体)

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5055 Problem Description Recently, Bob has been think ...

  4. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

  5. hdu 5012 模拟+bfs

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...

  6. hdu 5055(坑)

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=5055 Bob and math problem Time Limit: 2000/1000 MS ( ...

  7. hdu 4669 模拟

    思路: 主要就是模拟这些操作,用链表果断超时.改用堆栈模拟就过了 #include<map> #include<set> #include<stack> #incl ...

  8. 2013杭州网络赛C题HDU 4640(模拟)

    The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  9. HDU/5499/模拟

    题目链接 模拟题,直接看代码. £:分数的计算方法,要用double; #include <set> #include <map> #include <cmath> ...

随机推荐

  1. 01.VUE学习一

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...

  2. 用描述符实现classmethod方法和staticmethod方法

    1. @classmethod class ClassMethod: def __init__(self, func): self.func = func def __get__(self, inst ...

  3. 2017 ACM-ICPC网络赛 H.Skiing 有向图最长路

    H.Skiing In this winter holiday, Bob has a plan for skiing at the mountain resort. This ski resort h ...

  4. B1056 组合数的和 (15分)

    B1056 组合数的和 (15分) 给定 N 个非 0 的个位数字,用其中任意 2 个数字都可以组合成 1 个 2 位的数字.要求所有可能组合出来的 2 位数字的和.例如给定2.5.8,则可以组合出: ...

  5. lua table长度解析

    先来看lua table源码长度获取部分(ltable.c) j是数组部分的长度.首先判断数组长度大于0,并且数组最后一个是nil,就用二分法查找,返回长度. 如果t->node是 table的 ...

  6. Azure继续降价云 价格战就此终结?

    [TechTarget中国原创] 刚刚跨入2016年,就听到了云降价这样一个消息,但是我们却不要期望降价之风如去年一样呼呼不绝. 微软公司在本周宣称,他们将在下个月对其D系列虚拟机实施高达17%的降价 ...

  7. 成为谷歌的java程序员首先要做到这五点!

    成为谷歌的java程序员首先要做到这五点! 在现在,就是现在,程序员称霸武林,但是这是一个现实的社会,并没有天下第一这么一说,总是人外有人山外有山,想要成为谷歌程序员,你还要听听谷歌员工给的5个重要建 ...

  8. Win7系统安装MySQL5.5.21图解

    Win7系统安装MySQL5.5.21图解 大家都知道MySQL是一款中.小型关系型数据库管理系统,很具有实用性,对于我们学习很多技术都有帮助,前几天我分别装了SQL Server 2008和Orac ...

  9. 【LoadRunner】对摘要认证的处理

    近期项目中,进行http协议的接口性能测试过程中,需要进行登录接口的摘要认证,分享一下测试经验. 测试准备 测试工具:LoadRunner11 测试类型:接口测试--某系统登录接口 步骤 根据系统接口 ...

  10. 使用CoreLocation进行定位(Swift版)

    在应用开发中,很多情况需要我们获取到当前的位置和高度信息,方便搜索周边,查看周边相同应用等,一切与定位有关的都得使用CoreLocation库,而且,系统是不允许第三发定位的,当然可以使用第三方对其封 ...