各个位上的数字加和能被9整除,这个数就能被9整除,然后只要再在后边加个0,就可以被90整除了。
以前只知道3,看来要也要看看其他数字的倍数特性了
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
int num;
int zero;
int five;
int main()
{
ios::sync_with_stdio(false);
int n;
cin >> n;
for(int i = 0; i < n; ++i)
{
cin >> num;
if(num == 5) ++five;
else ++zero;
}
while(five)
{
if(five*5%9 == 0)
break;
five--;
}
if(five == 0 && zero == 0)
cout << -1 <<endl;
else if(five != 0 && zero == 0)
cout << -1 << endl;
else if(five == 0 && zero != 0)
cout << 0 << endl;
else
{
for(int i = 0; i < five; ++i) cout << 5;
for(int i = 0; i < zero; ++i) cout << 0;
cout << endl;
}
return 0;
}