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;
    }
  • 相关阅读:
    删除MFC单文档默认菜单栏的两种方法
    mfc更改背景色
    (转)VC单选按钮控件(Radio Button)用法
    转:MFC 基于对话的程序界面显示完全后立即执行一个函数
    转:vc6以上如何给MFC对话框添加OnInitDialog函数
    常用网址
    2010年春季学期C语言程序设计答疑安排
    rdlc导出Excel
    SQL Server查询表的结构
    C# WinForm开发系列 WebBrowser
  • 原文地址:https://www.cnblogs.com/zhangfengnick/p/4427245.html
Copyright © 2011-2022 走看看