博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
codeforces305A
阅读量:5099 次
发布时间:2019-06-13

本文共 3763 字,大约阅读时间需要 12 分钟。

Strange Addition

 

Unfortunately, Vasya can only sum pairs of integers (ab), such that for any decimal place at least one number has digit 0 in this place. For example, Vasya can sum numbers 505 and 50, but he cannot sum 1 and 4.

Vasya has a set of k distinct non-negative integers d1, d2, ..., dk.

Vasya wants to choose some integers from this set so that he could sum any two chosen numbers. What maximal number of integers can he choose in the required manner?

Input

The first input line contains integer k (1 ≤ k ≤ 100) — the number of integers.

The second line contains k distinct space-separated integers d1, d2, ..., dk (0 ≤ di ≤ 100).

Output

In the first line print a single integer n the maximum number of the chosen integers. In the second line print n distinct non-negative integers — the required integers.

If there are multiple solutions, print any of them. You can print the numbers in any order.

Examples

Input
4 100 10 1 0
Output
4 0 1 10 100
Input
3 2 70 3
Output
2 2 70 sol:我太菜了,只会分类讨论一大堆情况qaq,简直就是个智障
#include 
using namespace std;typedef int ll;inline ll read(){ ll s=0; bool f=0; char ch=' '; while(!isdigit(ch)) { f|=(ch=='-'); ch=getchar(); } while(isdigit(ch)) { s=(s<<3)+(s<<1)+(ch^48); ch=getchar(); } return (f)?(-s):(s);}#define R(x) x=read()inline void write(ll x){ if(x<0) { putchar('-'); x=-x; } if(x<10) { putchar(x+'0'); return; } write(x/10); putchar((x%10)+'0'); return;}#define W(x) write(x),putchar(' ')#define Wl(x) write(x),putchar('\n')const int N=105;int n,a[N],Id[10]={
0};inline void put0(int n){ int i; for(i=1;i<=n;i++) W(0);}int main(){ int i,j,ans=0; R(n); for(i=1;i<=n;i++) { R(a[i]); if(a[i]==0) ans++;//000 else if(a[i]<10) Id[1]=i;//00x else if(a[i]<100) { if(a[i]%10==0) Id[2]=i;//0x0 else Id[3]=i; //0xx } else { if(a[i]%100==0) Id[4]=i;//x00 else if(a[i]%10==0) Id[5]=i; //xx0; else if((a[i]-a[i]%10)%100==0) Id[6]=i; //x0x else Id[7]=i; //xxx } } if(Id[1]) { if(Id[2]) { if(Id[4]) { Wl(ans+3); put0(ans); W(a[Id[1]]); W(a[Id[2]]); W(a[Id[4]]); } else { Wl(ans+2); put0(ans); W(a[Id[1]]); W(a[Id[2]]); } } else { if(Id[4]) { Wl(ans+2); put0(ans); W(a[Id[1]]); W(a[Id[4]]); } else if(Id[5]) { Wl(ans+2); put0(ans); W(a[Id[1]]); W(a[Id[5]]); } else { Wl(ans+1); put0(ans); W(a[Id[1]]); } } } else if(Id[2]) { if(Id[4]) { Wl(ans+2); put0(ans); W(a[Id[2]]); W(a[Id[4]]); } else if(Id[6]) { Wl(ans+2); put0(ans); W(a[Id[2]]); W(a[Id[6]]); } else { Wl(ans+1); put0(ans); W(a[Id[2]]); } } else if(Id[4]) { if(Id[3]) { Wl(ans+2); put0(ans); W(a[Id[4]]); W(a[Id[3]]); } else { Wl(ans+1); put0(ans); W(a[Id[4]]); } } else if(Id[3]) { Wl(ans+1); put0(ans); W(a[Id[3]]); } else if(Id[5]) { Wl(ans+1); put0(ans); W(a[Id[5]]); } else if(Id[6]) { Wl(ans+1); put0(ans); W(a[Id[6]]); } else if(Id[7]) { Wl(ans+1); put0(ans); W(a[Id[7]]); } else { Wl(ans); put0(ans); } return 0;}/*Input4100 10 1 0Output40 1 10 100 Input32 70 3Output22 70 */
View Code

 

 

转载于:https://www.cnblogs.com/gaojunonly1/p/10753277.html

你可能感兴趣的文章
Thrift Expected protocol id ffffff82 but got 0
查看>>
【2.2】创建博客文章模型
查看>>
Kotlin动态图
查看>>
从零开始系列之vue全家桶(1)安装前期准备nodejs+cnpm+webpack+vue-cli+vue-router
查看>>
Jsp抓取页面内容
查看>>
大三上学期软件工程作业之点餐系统(网页版)的一些心得
查看>>
可选参数的函数还可以这样设计!
查看>>
[你必须知道的.NET]第二十一回:认识全面的null
查看>>
Java语言概述
查看>>
关于BOM知识的整理
查看>>
使用word发布博客
查看>>
面向对象的小demo
查看>>
微服务之初了解(一)
查看>>
GDOI DAY1游记
查看>>
收集WebDriver的执行命令和参数信息
查看>>
数据结构与算法(三)-线性表之静态链表
查看>>
mac下的mysql报错:ERROR 1045(28000)和ERROR 2002 (HY000)的解决办法
查看>>
Hmailserver搭建邮件服务器
查看>>
django之多表查询-2
查看>>
快速幂
查看>>