Codeforces Round #204 (Div. 2) A. Jeff and Digits
来源:互联网 发布:java sso单点登录 编辑:程序博客网 时间:2024/05/23 01:05
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.
The first line contains integer n (1 ≤ n ≤ 103). The next line contains n integers a1, a2, ..., an (ai = 0 or ai = 5). Number airepresents the digit that is written on the i-th card.
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.
45 0 5 0
0
115 5 5 5 5 5 5 5 0 5 5
5555555550
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.
#include <iostream>#include <stdio.h>#include <string.h>using namespace std;int main(){ int a[30],n,i,x; while(scanf("%d",&n)!=EOF){ a[0]=a[5]=0; for(i=0;i<n;i++){ scanf("%d",&x); a[x]++; } int tttt=a[5]/9; if(tttt&&a[0]){ tttt=tttt*9; for(i=0;i<tttt;i++){ printf("5"); } for(i=0;i<a[0];i++) printf("0"); printf("\n"); } else{ if(a[0])printf("0\n"); else printf("-1\n"); } } return 0;}
- Codeforces Round #204 (Div. 2) A. Jeff and Digits
- Codeforces Round #204 (Div. 2) A Jeff and Digits
- Codeforces Round #204 (Div. 1) A. Jeff and Rounding
- Codeforces Round #204 (Div. 2) B. Jeff and Periods
- Codeforces Round #204 (Div. 2) C. Jeff and Rounding
- Codeforces Round #204 (Div. 2) C Jeff and Rounding
- Codeforces Round #204 (Div. 2) B - Jeff and Periods
- CodeForces 352A Jeff and Digits
- CodeForces-352A Jeff and Digits
- Codeforces Round #204 (Div. 1) E. Jeff and Permutation
- A. Jeff and Digits
- CF#204DIV2:A. Jeff and Digits
- Codeforces Round #204 (Div. 1) C Jeff and Brackets dp+矩阵加速
- Codeforces Round #204 (Div. 1) B. Jeff and Furik 1月7日
- Codeforces Round #277.5 (Div. 2) C. Given Length and Sum of Digits...
- Codeforces Round #277.5 (Div. 2)C——Given Length and Sum of Digits...
- Codeforces Round #277.5 (Div. 2)---C. Given Length and Sum of Digits (贪心)
- Codeforces Round #277.5 (Div. 2) C Given Length and Sum of Digits...
- 【Java工程师之路】[1-1.2]Java开发和运行环境的搭建
- 关于通过不含虚析构函数的基类类型的指针删除派生类对象的问题
- cin.ignore()函数的用法
- POJ 3067 - Japan 树状数组~细心估计数据范围
- 课堂、课外和假期
- Codeforces Round #204 (Div. 2) A. Jeff and Digits
- Codeforces Round #204 (Div. 2) B. Jeff and Periods
- 追寻大学的理性
- 怎样写好一份IT技术岗位的简历
- 面向对象知识点
- asp.net 的那点事(2、浏览器和一般处理程序)
- ubuntu 12.04系统黑屏,登录界面黑屏,命令行界面可用
- (pojstep1.1.1)poj 1298(直叙式模拟)
- 最大连续递增数字串