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.

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 ;
}

A. Jeff and Digits(cf)的更多相关文章

  1. cf A. Jeff and Digits

    http://codeforces.com/contest/352/problem/A #include <cstdio> #include <cstring> #includ ...

  2. CF352A Jeff and Digits

    Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and ...

  3. B. Jeff and Periods(cf)

    B. Jeff and Periods time limit per test 1 second memory limit per test 256 megabytes input standard ...

  4. 『题解』Coderforces352A Jeff and Digits

    更好的阅读体验 Portal Portal1: Codeforces Portal2: Luogu Description Jeff's got n cards, each card contains ...

  5. codeforces A. Jeff and Digits 解题报告

    题目链接:http://codeforces.com/problemset/problem/352/A 题目意思:给定一个只有0或5组成的序列,你要重新编排这个序列(当然你可以不取尽这些数字),使得这 ...

  6. Codeforces Round #204 (Div. 2) A.Jeff and Digits

    因为数字只含有5或0,如果要被90整除的话必须含有0,否则输出-1 如果含有0的话,就只需考虑组合的数字之和是9的倍数,只需要看最大的5的个数能否被9整数 #include <iostream& ...

  7. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding

    http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...

  8. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation

    http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...

  9. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik

    http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...

随机推荐

  1. Centos7搭建lamp环境

    首先安装apache Centos7默认已经安装httpd服务,只是没有启动. 如果需要重新安装,输入 yum install -y httpd 启动服务: systemctl start httpd ...

  2. office 2016最新安装及激活教程(KMS)【亲测有效】!!

    前言 博主的一个朋友,咳咳--你们懂得,想装office,于是我就上网找了一下激活的方法,亲测有效,而且也没有什么广告病毒之类的,还比较方便,所以传上来方便大家.好了,进入正题: 安装office 首 ...

  3. mysql登录出现1045错误

    这个问题是在window server 2012上安装mysql之后, 远程访问时出现的1045错误 我新建了一个相同的用户用于远程访问, 密码也相同, 但是还是访问不了 参照链接:https://b ...

  4. git 的简单使用(4)

    多人协作的工作模式通常是这样: 首先,可以试图用git push origin <branch-name>推送自己的修改: 如果推送失败,则因为远程分支比你的本地更新,需要先用git pu ...

  5. python json结构

    =====================================================json==============================import reques ...

  6. 微信公众号:1-IDHTTP控件:GET/POST 请求获取access_token

    (图来源于方蓓?) 首先要理解公众号的流程.通过图知道,我们要:1.你要有个web服务器,用于和微信服务器通讯.你的web服务器必须让微信服务器能找到.2.通信要求按照微信公众号开发要求的格式提供相关 ...

  7. Python之路【第一篇】:Python基础1

    本节内容 Python介绍 发展史 Python 2 or 3? 安装 Hello World程序 变量 用户输入 模块初识 .pyc是个什么鬼? 数据类型初识 数据运算 表达式if ...else语 ...

  8. [BZOJ 4563]放棋子

    [BZOJ 4563]放棋子 题目 给你一个N*N的矩阵,每行有一个障碍,数据保证任意两个障碍不在同一行,任意两个障碍不在同一列,要求你在这个矩阵上放N枚棋子(障碍的位置不能放棋子),要求你放N个棋子 ...

  9. 977. Squares of a Sorted Array

    题目描述: Given an array of integers A sorted in non-decreasing order, return an array of the squares of ...

  10. IntelliJ IDEA 给表达式赋变量名称

    IntelliJ IDEA 给表达式赋变量名称 学习了:http://blog.csdn.net/tiny__wang/article/details/52988790 类似于Eclipse中的ctr ...