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;
    }
  • 相关阅读:
    【疑难系列】 是程序卡住了还是怎么了?
    【疑难系列】 一个看起来是数据库死锁的问题
    求求别再这么用log4x了
    如何动态在spring mvc中增加bean
    java中被各种XXUtil/XXUtils辅助类恶心到了,推荐这种命名方法
    少搞点语法糖,多写点功能
    记一次在java中的日期parse错误
    《自控力》读后感·一
    实现数据权限控制的一种方法
    10个必会的 PyCharm 技巧
  • 原文地址:https://www.cnblogs.com/zhangfengnick/p/4427245.html
Copyright © 2011-2022 走看看