• Codeu_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


    这道题是一道细节题;我开始只设置了50,后来改成100就可以AC了,简直是心累。
    AC代码:
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #define Max 1005
    using namespace std;
    
    struct people
    {
        char number[100];
        char name[100];
        char sex[10];
        int age;
    }person[Max];
    
    int main(void)
    {
        freopen("in.txt","r",stdin);
        int n;
        long long m;
        int count;
        char st[50];
        while(scanf("%d",&n)!=EOF)
        {
            for(int i=1;i<=n;i++)
                scanf("%s%s%s%d",person[i].number,person[i].name,person[i].sex,&person[i].age);
            scanf("%lld",&m);
            while(m--)
            {
                count=0;
                scanf("%s",st);
                for(int i=1;i<=n;i++)
                {
                    if(strcmp(st,person[i].number)==0)
                    {
                        printf("%s %s %s %d
    ",person[i].number,person[i].name,person[i].sex,person[i].age);
                        count=1;
                        break;
                    }
                }
                if(count==0)
                    printf("No Answer!
    ");
            }
            
        }
        
    
        fclose(stdin);
        return 0;
    }
  • 相关阅读:
    python基础(6)---set、collections介绍
    Vue Router滚动行为 scrollBehavior
    CSS expression属性
    定时器setTimeout实现函数节流
    axios封装
    vue项目结构
    搭建vue项目环境
    javascript参数传递中处理+号
    微信支付 chooseWXPay:fail
    微信支付get_brand_wcpay_request:fail
  • 原文地址:https://www.cnblogs.com/phaLQ/p/10080905.html
Copyright © 2020-2023  润新知