A. Search for Pretty Integers

题目链接:http://codeforces.com/contest/872/problem/A

题目意思:题目很简单,找到一个数,组成这个数的数字即在A数组中出现过,也在B数组中出现过,问这个数最小是多少。

题目思路:首先要么一个数两个数组都出现过直接输出来,要么分别取两个数组中最小的数组合一下输出。

代码:

 1 //Author: xiaowuga
 2 #include <bits/stdc++.h>
 3 using namespace std;
 4 #define inf 0x3f3f3f3f
 5 #define MAX INT_MAX
 6 #define mem(s,ch) memset(s,ch,sizeof(s))
 7 const long long N=100000; 
 8 const long long mod=1e9+7; 
 9 typedef long long LL;
10 typedef int II;
11 typedef unsigned long long ull;
12 #define nc cout<<"nc"<<endl
13 #define endl "\n"
14 int main() {
15     ios::sync_with_stdio(false);cin.tie(0);
16     int a=20,b=20;
17     int n,m;
18     int aa[10]={0},bb[10]={0};
19     cin>>n>>m; 
20     for(int i=0;i<n;i++){
21         int t;
22         cin>>t;
23         a=min(a,t);
24         aa[t]=1;
25     } 
26     for(int i=0;i<m;i++){
27         int t;
28         cin>>t;
29         b=min(b,t);
30         bb[t]=1;
31     } 
32     for(int i=1;i<=9;i++){
33         if(aa[i]&&bb[i]){
34             cout<<i<<endl;
35             return 0;
36         }
37     } 
38     if(a>b) swap(a,b);
39     cout<<(a*10)+b<<endl;
40     return 0;
41 }
View Code

相关文章: