zoukankan      html  css  js  c++  java
  • 1761: 学生信息删除

    #include<stdio.h>
    struct student
    {
    long no;
    char name[9];
    int score;
    };
    void input(struct student stu[100],int n)
    {
    int i;
    for(i=0;i<n;i++)
    {
    scanf("%ld %s %d",&stu[i].no,&stu[i].name,&stu[i].score);
    }
    return;
    }
    int delet(struct student stu[],int n,long xh)
    {
    int i, flag=1,j;
    for(i=0;i<n;i++)
    {
    if(stu[i].no==xh)
    {
    for(j=i;j<n;j++)
    {
    stu[j]=stu[j+1];
    }
    return 1;
    flag=0;
    }
    }if(flag) return -1;

    }
    void print(struct student stu[],int n)
    {
    int i;
    for(i=0;i<n;i++)
    {
    printf("%ld %s %d ",stu[i].no,stu[i].name,stu[i].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=delet(stu,n,xh); //删除学号为xh的学生,删除不成功返回-1,删除成功则返回1
    if(t==-1)
    printf("delete Failed ",xh);
    else
    {
    n--;
    printf("delete Success ");
    }
    }
    print(stu,n); //输出n个学生的信息
    }
    return 0;
    }

  • 相关阅读:
    线程的等待与唤醒
    多线程start()与run()的区别
    Thread与Runnable
    关于i++和++i的一些见解
    Mysql优化(转)
    Java 注解
    Java 泛型(转)
    Java 中的CAS
    CAS ABA问题
    Java 线程池分析
  • 原文地址:https://www.cnblogs.com/cy846586184/p/12288471.html
Copyright © 2011-2022 走看看