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; }
  • 相关阅读:
    win10系统设置指定程序开机自启
    PyCharm 2020.1 x64 专业版破解【亲测有效】
    xampp_mysql数据库root登录报错1045-Access denied for user 'root'@'localhost' (using password:YES)
    关于 Tomcat 启动时,解决控制台输出日志乱码问题的方案
    1.css选择器
    5.canvas
    4.音频与视频
    3.form表单
    淘宝店铺设计
    2.html5新布局元素
  • 原文地址:https://www.cnblogs.com/zmx354/p/3143155.html
Copyright © 2011-2022 走看看