题解 P2192 【HXY玩卡片】
JustinRochester · · 题解
题目
本题其实就几个坑点,一看懂就过了
①选择的是一些卡片(也就是说可以有一部分不选)
②数字不可以有前导0,但可以直接为0啊(见样例1)
那就直接开始分析了:
①必须为
且根据小学学的知识,
②数字要尽量大,则需要在满足上述条件的情况下尽量多的放 (感谢C++ int型的自动向下取整2333)。同时,有 (越多越好)。
③由上面的分析可得,我们只要维护
好的,那么我这个蒟蒻就放代码了。
#include<cstdio>
using namespace std;
int main(){
int n,count5=0,count0=0;
scanf("%d",&n);
while(n--){
int x;scanf("%d",&x);
if(x==5) count5++;if(x==0) count0++;
}
if(count5<9){
if(count0==0) { printf("-1"); return 0; }
else { printf("0"); return 0; }
}
if(count0==0) { printf("-1"); return 0; }
for(int i=0;i<(count5/9)*9;i++) printf("5");
while(count0--) printf("0");
return 0;
}
最后安利一下 本蒟蒻的博客