zoukankan      html  css  js  c++  java
  • 1763: 职工信息插入

    #include<stdio.h>
    struct employee
    {
    long no;
    char name[9];
    int birth[4];
    };
    void input(struct employee emp[100],int n)
    {
    int i;
    for(i=1;i<=n;i++)
    {
    scanf("%ld %s %d %d %d",&emp[i].no,emp[i].name,&emp[i].birth[1],&emp
    [i].birth[2],&emp[i].birth[3]);
    }
    return;
    }
    void insert(struct employee emp[],int n)
    {
    int i,j,k,f=0;
    struct employee t;
    scanf("%ld %s %d %d %d",&t.no,t.name,&t.birth[1],&t.birth[2],&t.birth[3]);
    for(i=1;i<=n;i++)
    {
    if(emp[i].birth[1]>t.birth[1] || emp[i].birth[1]==t.birth[1] && emp
    [i].birth[2]>t.birth[2] || emp[i].birth[1]==t.birth[1] && emp[i].birth[2]==t.birth[2] &&
    emp[i].birth[3]>t.birth[3])
    {
    f=1;
    for(j=n;j>=i;j--)
    {
    emp[j+1]=emp[j];
    }
    emp[i]=t;
    return;
    }
    }
    if(f==0)
    emp[n+1]=t;
    }
    void print(struct employee emp[100],int n)
    {
    int i;
    for(i=1;i<=n;i++)
    {
    printf("%ld %s %d-%d-%d ",emp[i].no,emp[i].name,emp[i].birth[1],emp
    [i].birth[2],emp[i].birth[3]);
    }
    return;
    }
    int main()
    {
    int i,n,m;
    struct employee emp[100];
    while(scanf("%d",&n)!=EOF)
    {
    input(emp,n); //读入n个职工的数据
    scanf("%d",&m);
    for(i=0;i<m;i++)
    {
    insert(emp,n); //录入一个职工的信息,然后将它插入到结构体数组中,仍然按出生日期有序
    n++;
    }
    print(emp,n); //输出n个职工的信息
    }
    return 0;
    }

  • 相关阅读:
    PythonStudy——格式化输入小练习
    PythonStudy——运算符优先级 Operator precedence
    PythonStudy——逻辑运算符 Logical Operators
    ExtJS动态创建组件
    常见报表的JS代码
    sqlserver学习
    读写分离与锁分离
    oracle链接原理
    读java并发编程笔记
    日志机制在编程中的作用
  • 原文地址:https://www.cnblogs.com/cy846586184/p/12288672.html
Copyright © 2011-2022 走看看