SDUT—2057 模拟题

发布时间:2016-12-9 19:40:32 编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"SDUT—2057 模拟题",主要涉及到SDUT—2057 模拟题方面的内容,对于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("\n#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("\n#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("\n"); } 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; }  

上一篇:绘图基础--椭圆
下一篇:SDUT1482——二元多项式

相关文章

相关评论