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;
    }
  • 相关阅读:
    自制404页面
    Http错误代码含义
    数据访问基础类(基于Access数据库)
    NTILE函数在SQL Server 2000中的实现方法
    矩阵螺旋输出
    分区排名方案和排名值效率分析【图文+测试代码】
    安装eclipse axis2 插件(links 方式)
    perforce关闭服务后无法重启
    A4纸网页打印中对应像素的设定和换算
    2005数据库脚本在SQL2000上执行
  • 原文地址:https://www.cnblogs.com/zhangfengnick/p/4427245.html
Copyright © 2011-2022 走看看