zoukankan      html  css  js  c++  java
  • SDUT—2057 模拟题

    #include <cstdio>
    #include <cstring>
    #include <cstdlib>
    #include <iostream>
    #include <algorithm>
    
    using namespace std;
    
    struct N
    {
        int data;
        char name[21];
        N *next;
    };
    
    N *creat()
    {
        N *p = (struct N *)malloc(sizeof(struct N));
        p->next = NULL;
        return p;
    }
    
    void link(N *head,N *p)
    {
        N *q = head;
        for(;q->next != NULL && q->next->data >= p->data; q = q->next);
        p->next = q->next;
        q->next = p;
    }
    
    int del(N *head,char *name)
    {
        N *p = head;
        N *q = head->next;
        for(;q->next != NULL && strcmp(name,q->name) != 0;p = p->next,q = q->next);
        p->next = q->next;
        return q->data;
    }
    
    void change(N *head,N *p)
    {
        p->data += del(head,p->name);
        link(head,p);
    }
    
    void output_rank(N *head)
    {
        int sum,temp;
        printf("#1 :");
        for(head = head->next,temp = head->data;head != NULL;)
        {
            if(temp == head->data)
            {
                printf(" %s",head->name);
                head = head->next;
            }
            else break;
        }
        if(head == NULL) return;
        printf("
    #2 :");
        for(temp = head->data,sum = 1;head != NULL;)
        {
            if(temp == head->data)
            {
                printf(" %s",head->name);
                head = head->next;
            }
            else
            {
                sum++;
                if(sum <= 2)
                {
                    temp = head->data;
                    printf(" %s",head->name);
                    head = head->next;
                }
                else break;
            }
        }
        if(head == NULL) return;
        printf("
    #3 :");
        for(temp = head->data,sum = 1;head != NULL;)
        {
            if(temp == head->data)
            {
                printf(" %s",head->name);
                head = head->next;
            }
            else
            {
                sum++;
                if(sum <= 3)
                {
                    temp = head->data;
                    printf(" %s",head->name);
                    head = head->next;
                }
                else break;
            }
        }
        printf("
    ");
    }
    
    void output(N *head)
    {
        for(N *p = head->next; p != NULL; p = p->next)
        cout<<p->name<<' '<<p->data<<endl;
    }
    
    int main()
    {
        int n;
        N *head = creat();
        cin>>n;
        for(int i = 0;i < n; i++)
        {
            N *p = creat();
            cin>>p->name>>p->data;
            link(head,p);
        }
    
        char order;
        while(cin>>order && order != 'O')
        {
            if(order == 'A')
            {
                N *p = creat();
                cin>>p->name>>p->data;
                link(head,p);
            }
            else if(order == 'Q')
            {
                char name[21];
           cin>>name; del(head,name); }
    else if(order == 'C') { N *p = creat(); cin>>p->name>>p->data; change(head,p); } else if(order == 'S') { output(head); } } output_rank(head); return 0; }
  • 相关阅读:
    使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
    高性能 Windows Socket 组件 HPSocket
    Linux下的C编程实战
    Scrum实践
    hadoop之NameNode,DataNode,Secondary NameNode
    代码抽象层次
    分布式统计的思考以及实现
    GCC起步
    学习 easyui 之一:easyloader 分析与使用
    从Prism中学习设计模式之MVVM 模式简述MVVM
  • 原文地址:https://www.cnblogs.com/zmx354/p/3143155.html
Copyright © 2011-2022 走看看