CF--518A--Strange Addition

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.

Example
Input
4
100 10 1 0
Output
4
0 1 10 100 
Input
3
2 70 3
Output
2
2 70 

题意:

给你两个字符串a和b,求出一个字符串c,按字典序,满足a<c<b;

解题思路:

因为a<b,所以从头到尾对a进行遍历,遇到小于'z'的元素时,把a复制到c里面,把c里面对应的元素加一,后面全部置为a,那么此时c一定是大于a的,再用c于b进行比较,如果满足c<b;那么答案就出来了,如果不满足 就继续对a进行遍历。

代码:

 C++ Code 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include<bits/stdc++.h>
using namespace std;

char s[105], t[105], ans[105];
int main()
{
    bool flag = false;
    scanf("%s %s", s, t);
    int len = strlen(s);
    for(int i = 0; i < len; i++)
    {
        if(s[i] != 'z')
        {
            strcpy(ans, s);
            ans[i]++;
            for(int j = i + 1; j < len; j++)
                ans[j] = 'a';
            if(strcmp(ans, t) < 0)
            {
                flag = true;
                break;
            }
        }
    }
    printf("%s\n", flag ? ans : "No such string");
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值