A - 0和5

小K手中有n张牌,每张牌上有一个一位数的数,这个字数不是0就是5。小K从这些牌在抽出任意张(不能抽0张),排成一行这样就组成了一个数。使得这个数尽可能大,而且可以被90整除。

注意:

1.这个数没有前导0,

2.小K不需要使用所有的牌。

Input

每个测试数据输入共2行。 
第一行给出一个n,表示n张牌。(1<=n<=1000) 
第二行给出n个整数a00,a11,a22,…,an−1n−1 (aii是0或5 ) 表示牌上的数字。

Output

共一行,表示由所给牌组成的可以被90整除的最大的数,如果没有答案则输出”-1”(没有引号)

Sample Input

4
5 0 5 0

Sample Output

0
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
int main()
{
    int n,i,a=0,b=0;
    cin>>n;
    for(i=0; i<n; i++)
    {
        int t;
        cin>>t;
        if(t==0)a++;
        else b++;
    }
    if(a==0)cout<<"-1"<<endl;
    else
    {
        if(b<9)cout<<"0"<<endl;
        else
        {
            int x=b/9;
            while(x)
            {
                cout<<"555555555";
                x--;
            }
            for(i=0; i<a; i++)
                cout<<"0";
            cout<<endl;
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_41374539/article/details/82024943