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;
    }
  • 相关阅读:
    LeetCode113. 路径总和 II
    LeetCode257. 二叉树的所有路径
    LeetCode222. 完全二叉树的节点个数
    LeetCode404. 左叶子之和
    LeetCode110. 平衡二叉树
    LeetCode101. 对称二叉树
    LeetCode100. 相同的树
    llustrator CC2017下载AI2020
    vs code 代码格式化整理
    人生格言
  • 原文地址:https://www.cnblogs.com/zhangfengnick/p/4427245.html
Copyright © 2011-2022 走看看