zoukankan      html  css  js  c++  java
  • 【排序,先入先出】Windows Message Queue

    Windows Message Queue

    Time Limit: 1 Sec  Memory Limit: 64 MB Submit: 73  Solved: 41 [Submit][Status][Discuss]

    Description

    Message queue is the basic fundamental of windows system. For each process, the system maintains a message queue. If something happens to this process, such as mouse click, text change, the system will add a message to the queue. Meanwhile, the process will do a loop for getting message from the queue according to the priority value if it is not empty. Note that the less priority value means the higher priority. In this problem, you are asked to simulate the message queue for putting messages to and getting message from the message queue.

    Input

    There's only one test case in the input. Each line is a command, "GET" or "PUT", which means getting message or putting message. If the command is "PUT", there're one string means the message name and two integer means the parameter and priority followed by. There will be at most 60000 command. Note that one message can appear twice or more and if two messages have the same priority, the one comes first will be processed first.(i.e., FIFO for the same priority.) Process to the end-of-file.

    Output

    For each "GET" command, output the command getting from the message queue with the name and parameter in one line. If there's no message in the queue, output "EMPTY QUEUE!". There's no output for "PUT" command.

    Sample Input

    GET
    PUT msg1 10 5
    PUT msg2 10 4
    GET
    GET
    GET
    

    Sample Output

    EMPTY QUEUE!
    msg2 10
    msg1 10
    EMPTY QUEUE!
    

    HINT

    zoj2724

    Source

    [Submit][Status][Discuss]

    HOME Back

    就是定义数组a【60002】,从而完成优先级相同,先入先出,不过不是最简,有待改进

    #include <stdio.h>
    struct Pail
    {
        char str[120];
        int c,q;
    }s[60066];
    int main()
    {
        char a[4];
        int k=0,i,temp,t,x[60009]={0},c;
        while(scanf("%s",a)!=EOF)
        {
            if(a[0]=='G')
            {
                c=0;
                for(i=0;i<=k;i++)
                    if(x[i]==1)
                    {
                        temp=i;
                        t=s[i].q;
                        c=1;
                    }
                if(c==0)
                    printf("EMPTY QUEUE!
    ");
                else
                {
                for(i=0;i<=k;i++)
                {
                    if(t>s[i].q&&x[i]==1)
                    {
                        t=s[i].q;
                        temp=i;
                    }
                }
                printf("%s %d
    ",s[temp].str,s[temp].c);x[temp]=0;
                }
            }
            if(a[0]=='P')
            {
                scanf("%s %d %d",s[k].str,&s[k].c,&s[k].q);x[k]=1;
                k++;
            }
        }
        return 0;
    }
  • 相关阅读:
    linux添加开机启动项、登陆启动项、定时启动项、关机执行项等的方法
    linux下/etc/rc.d目录的介绍及redhat启动顺序
    Linux开机自动挂载存储的两种方式
    Linux中环境变量文件profile、bashrc、bash_profile之间的区别和联系
    linux命令详解——yum
    linux命令详解——ftp
    Shell脚本之sed详解
    shell awk读取文件中的指定行的指定字段
    MySQL的字符集
    shell脚本中的数组
  • 原文地址:https://www.cnblogs.com/zhangfengnick/p/4427245.html
Copyright © 2011-2022 走看看