Codeup_576_问题 D: 查找

题目描述

输入数组长度 n  输入数组      a[1...n]  输入查找个数m  输入查找数字b[1...m]  输出 YES or NO  查找有则YES 否则NO 。

输入

输入有多组数据。 每组输入n,然后输入n个整数,再输入m,然后再输入m个整数(1<=m<=n<=100)。

输出

如果在n个数组中输出YES否则输出NO。

样例输入

6
3 2 5 4 7 8
2
3 6

样例输出

YES
NO

此题需注意输出时的大小写:
#include <iostream>
#include <cstdio>
#define Max 105
using namespace std;

long long a[Max];
long long b[Max];
int main(void)
{
    freopen("in.txt","r",stdin);
    int n,m;
    while(scanf("%d",&n)!=EOF)
    {
        for(int i=1;i<=n;i++)
            scanf("%lld",&a[i]);
        
        scanf("%d",&m);
        for(int i=1;i<=m;i++)
            scanf("%lld",&b[i]);
            
        int k=1;
        int count;
        while(k<=m)
        {
            count=0;
            for(int j=1;j<=n;j++)
            {
                if(b[k]==a[j])
                {
                    count=1;
                    printf("YES
");
                    break;
                }
            }
            
            k++;
            if(count==0)
                printf("NO
");
        }
    }
    

    fclose(stdin);
    return 0;
}
原文地址:https://www.cnblogs.com/phaLQ/p/10080909.html