Strange Addition
Unfortunately, Vasya can only sum pairs of integers (a, b), 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?
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).
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.
4 100 10 1 0
4 0 1 10 100
3 2 70 3
2 2 70
题意:
给你两个字符串a和b,求出一个字符串c,按字典序,满足a<c<b;
解题思路:
因为a<b,所以从头到尾对a进行遍历,遇到小于'z'的元素时,把a复制到c里面,把c里面对应的元素加一,后面全部置为a,那么此时c一定是大于a的,再用c于b进行比较,如果满足c<b;那么答案就出来了,如果不满足 就继续对a进行遍历。
代码:
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; } |