题意翻译
给出两个整数n,m,a数组有n个数,b数组有m个数。求一个数,这个数的每一位必须在a数组和b数组中至少出现过一次,求符合条件的数当中最小的数。
Translated by @我是lyy
题目描述
You are given two lists of non-zero digits.
Let's call an integer pretty if its (base 1010 ) representation has at least one digit from the first list and at least one digit from the second list. What is the smallest positive pretty integer?
输入输出格式
输入格式:
The first line contains two integers nn and mm ( 1<=n,m<=91<=n,m<=9 ) — the lengths of the first and the second lists, respectively.
The second line contains nn distinct digits a_{1},a_{2},...,a_{n}a1,a2,...,an ( 1<=a_{i}<=91<=ai<=9 ) — the elements of the first list.
The third line contains mm distinct digits b_{1},b_{2},...,b_{m}b1,b2,...,bm ( 1<=b_{i}<=91<=bi<=9 ) — the elements of the second list.
输出格式:
Print the smallest pretty integer.
输入输出样例
说明
In the first example 2525 , 4646 , 2456724567 are pretty, as well as many other integers. The smallest among them is 2525 . 4242 and 2424are not pretty because they don't have digits from the second list.
In the second example all integers that have at least one digit different from 99 are pretty. It's obvious that the smallest among them is 11 , because it's the smallest positive integer.
#include<cmath> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int n,m; int a[11],b[11]; int main(){ cin>>n>>m; for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=1;i<=m;i++) scanf("%d",&b[i]); sort(a+1,a+1+n); sort(b+1,b+1+m); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) if(a[i]==b[j]){ cout<<a[i]<<endl; return 0; } if(a[1]>b[1]) cout<<b[1]*10+a[1]<<endl; else cout<<a[1]*10+b[1]<<endl; }