首页 技术 正文
技术 2022年11月23日
0 收藏 498 点赞 2,601 浏览 1170 个字

A. Jeff and Digitstime 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.

Sample test(s)Input

4
5 0 5 0

Output

0

Input

11
5 5 5 5 5 5 5 5 0 5 5

Output

5555555550
 #include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int n,x;
while(~scanf("%d",&n))
{
int cnt5 = ,cnt0 = ,max = ;
while(n--)
{
scanf("%d",&x);
if (x==)
cnt5++;
else
cnt0++;
if(cnt5%==&&cnt5)//能被9整除的数其各位数之和是9的倍数,故5的个数应是9的倍数
{
if (cnt5 > max)
max = cnt5;
}
}
if (cnt0==)//能被90整除的数末尾必含0
puts("-1");
else if (!max)//若5的个数小于9个且cnt0!=0,则最大的数为0
puts("");
else
{
while(max--)
cout<<"";
while(cnt0--)
cout<<"";
puts("");
} }
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,997
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,511
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,356
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,139
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,770
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,848