博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #204 (Div. 2)->A. Jeff and Digits
阅读量:4969 次
发布时间:2019-06-12

本文共 1918 字,大约阅读时间需要 6 分钟。

A. Jeff and Digits
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and put them in a line so that he gets some number. What is the largest possible number divisible by 90 Jeff can make from the cards he's got?

Jeff must make the number without leading zero. At that, we assume that number 0 doesn't contain any leading zeroes. Jeff doesn't have to use all the cards.

Input

The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number ai represents the digit that is written on the i-th card.

Output

In a single line print the answer to the problem — the maximum number, divisible by 90. If you can't make any divisible by 90 number from the cards, print -1.

Examples
input
4 5 0 5 0
output
0
input
11 5 5 5 5 5 5 5 5 0 5 5
output
5555555550
Note

In the first test you can make only one number that is a multiple of 90 — 0.

In the second test you can make number 5555555550, it is a multiple of 90.

题意:给出n个数字,数字只有两种,0或者5,随意组合这些数字,问是否可以找到能组合出的数中能被90整除的最大的数。

题解:根据给出的样例,其实我们已经知道了前两个能被90整除的数,第一个是0,第二个是9个5加1个0,然后我们用计算器算一下,就可以知道,当5的个数是9的倍数并且有0存在时,这个数是可以整除90的,所以,只需要统计0和5的个数balabala(看代码....

#include
using namespace std;int n, k5 = 0, k0 = 0, tmp;int main() { cin >> n; for (int i = 0; i < n; ++i) { cin >> tmp; if(tmp == 5) k5++; else k0++; } if(k0 == 0) { cout << -1 << endl; return 0; } if(k5 < 9 && k0) { cout << 0 << endl; return 0; } if(k5) { int aa = k5 / 9; int bb = aa * 9; while(bb--) cout << 5; while(k0--) cout << 0; cout << endl; return 0; } return 0;}

 

转载于:https://www.cnblogs.com/zhien-aa/p/6021184.html

你可能感兴趣的文章
广播信道--CSMA/CD协议
查看>>
第二十六课
查看>>
Python基础之字符串拼接简单介绍
查看>>
redis-pipeline
查看>>
计蒜客---最大子阵列
查看>>
matlab的conv2、imfilter、filter2
查看>>
弗洛伊德算法(Floyd)
查看>>
xFire 开发web services
查看>>
设计类图
查看>>
类对象
查看>>
ios 上架流程
查看>>
ajax连接池和XMLHttpRequest
查看>>
[Voice communications] 声音的滤波
查看>>
BZOJ.3139.[HNOI2013]比赛(搜索 Hash)
查看>>
json在线解析
查看>>
存储设备形成的层次结构
查看>>
源码阅读 - java.util.concurrent (三)ConcurrentHashMap
查看>>
Daily Scrum 10.30
查看>>
SQL语言之概述(一)
查看>>
数据库表 copy
查看>>