zoukankan      html  css  js  c++  java
  • 1760: 学生信息查找

    #include<stdio.h>
    struct student
    {
    long no;
    char name[9];
    int score;
    } ;
    void input(struct student stu[],int n)
    {
    int j;
    for(j=0;j<n;j++)
    {
    scanf("%ld %s %d",&stu[j].no,&stu[j].name,&stu[j].score);
    }
    }
    int search(struct student stu[],int n,long xh)
    {
    int j,flag=1;
    for(j=0;j<n;j++)
    {
    if(stu[j].no==xh)
    {
    return j;
    flag=0;
    break;
    }
    }
    if(flag) return -1;
    }
    void print(struct student stu[],int t)
    {
    printf("%ld %s %d ",stu[t].no,stu[t].name,stu[t].score);
    }
    int main()
    {
    int i,n,m,t;
    long xh;
    struct student stu[100];
    while(scanf("%d",&n)!=EOF)
    {
    input(stu,n); //读入n个学生的数据
    scanf("%d",&m);
    for(i=0;i<m;i++)
    {
    scanf("%ld",&xh);
    t=search(stu,n,xh); //查找学号为xh的学生,不存在返回-1,存在则返回其下标
    if(t==-1)
    printf("%d not exist ",xh);
    else
    print(stu,t); //输出第t个学生的信息
    }
    }
    return 0;
    }

  • 相关阅读:
    Codeforces-754D Fedor and coupons
    LightOJ
    LightOJ
    LightOJ
    LightOJ
    POJ
    HDU
    HDU
    HDU-2159
    方法的重写
  • 原文地址:https://www.cnblogs.com/cy846586184/p/12288463.html
Copyright © 2011-2022 走看看