zoukankan      html  css  js  c++  java
  • codeforces305A

    Strange Addition

     CodeForces - 305A 

    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 <bits/stdc++.h>
    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('
    ')
    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;
    }
    /*
    Input
    4
    100 10 1 0
    Output
    4
    0 1 10 100 
    
    Input
    3
    2 70 3
    Output
    2
    2 70 
    */
    View Code
     
  • 相关阅读:
    Redis 在 分布式项目中 的小应用--分布式锁 模拟session 分布式自增id
    自动生成swagger 前后端分离 对接文档
    利用IDEA 把maven工程中spring-boot的某个模块打成jar包
    利用SQL语句,把本地Excel文件批量导入mysql数据库,做测试数据使用
    Java常用API-String类
    网络编程模型及TCP、UDP编程设计
    计算机网络模型构架分析
    多线程程序的设计详解
    多进程、进程间通讯设计
    Linux 文件编程、时间编程基本函数
  • 原文地址:https://www.cnblogs.com/gaojunonly1/p/10753277.html
Copyright © 2011-2022 走看看