• FCFS 先来先服务


    /*
    先来先服务FCFS

    要求:
    1>用结构体定义程序:程序号,优先数(到达时间),CPU运算所需时间

    2>输入进程序列

    3>按优先数高低排序输出
    */
    #include<stdio.h>
    #include<string.h>
    #define N 100
    typedef struct Time
    {
    int reachTime; //优先数(程序到达时间)
    int runningTime; //CPU运算时间
    }Time;

    typedef struct Information
    {
    long ID; //程序号

    Time pay;
    }INF;

    int n;
    void readpay(INF p[]);
    void DeSortbytheFirst(INF p[]);

    void main() //主函数
    {
    INF p[N];
    struct Time;
    int sum=0;
    int i;
    long number;
    printf("请输入程序个数:(<100个)");
    scanf("%d",&n);
    readpay(p);
    for(i=0;i<n;i++)
    {
    sum=sum+p[i].pay.reachTime+p[i].pay.runningTime;
    }
    printf("\n\n\t\t#####总周转时间为:%d毫秒#####\n\t\n",sum);

    DeSortbytheFirst(p);


    }

    void readpay(INF p[]) //1.输入程序资料
    {
    int i;
    for(i=0;i<n;i++)
    {
    printf("\n\t请输入第%d个程序号:\n",i+1);
    scanf("\t\t%ld",&p[i].ID);

    printf("请输入第%d个程序的到达时间:\n",i+1);
    scanf("\t\t%d",&p[i].pay.reachTime);

    printf("请输入第%d个程序的CPU运算时间:\n",i+1);
    scanf("\t\t%d",&p[i].pay.runningTime);

    printf("\t\n%10ld %d\t%d\t\n \t周转时间:%d\n",p[i].ID,p[i].pay.reachTime,p[i].pay.runningTime,p[i].pay.reachTime+p[i].pay.runningTime);

    }
    }

    void DeSortbytheFirst(INF p[]) //2.按优先级高到低排序输出
    {
    int i,j,k,last;
    int All;
    int a1,a2;
    INF temp;

    printf("\t####################按优先级高低排序输出##################\n\n");
    printf("\n\t程序号\t到达时间\t周转时间\n");

    for(i=0;i<n;i++)
    {
    k=i;
    for(j=i+1;j<=n;j++)
    {
    a1=p[i].pay.reachTime;
    a2=p[j].pay.reachTime;
    if(a1>a2)
    {
    temp=p[j];
    p[j]=p[i];
    p[i]=temp;
    }
    }

    for(k=1;k<n+1;k++)
    {
    All=p[k].pay.reachTime+p[k].pay.runningTime;
    last=k;
    }
    printf("%10ld\t%d\t\t%d\t\n",p[last].ID,p[last].pay.reachTime,All);
    }


    }

     

  • 相关阅读:
    读《构建之法》阅读与思考
    软工沉浮沉沉沉沉沉沉…记事
    四则运算截图and代码
    2016012000郭慕然+散列函数的应用及其安全性
    结对作业之四则运算网页版
    阅读《构建执法》第四章及第十七章有感
    2016012000小学四则运算练习软件项目报告
    有关读《构建之法》的部分思考与疑问
    遇见·软件
    我的——今日学习内容
  • 原文地址:https://www.cnblogs.com/maykok/p/5392542.html
Copyright © 2020-2023  润新知