#include "stdafx.h"
#include<iostream>
#include<string>
using namespace std;
typedef struct node {
string name;
string number;
int result;
struct node *next;
}NODE;
NODE *build(int n) {
NODE *head, *p, *nextnode;
head = new NODE;
head->next = NULL;
p = head;
for (int i = 0; i < n; i++) {
nextnode = new NODE;
cin >> nextnode->name;
cin >> nextnode->number;
cin >> nextnode->result;
p->next = nextnode;
p = nextnode;
}
p->next = NULL;
return head;
}
void sort(NODE *head) {
NODE *min = head->next, *max = head->next;
NODE *p;
for (p = head->next->next; p != NULL; p = p->next) {
if (p->result > max->result) {
max = p;
}
}
for (p = head->next->next; p != NULL; p = p->next) {
if (p->result < min->result) {
min = p;
}
}
cout << max->name << " " << max->number << endl;
cout << min->name << " " << min->number << endl;
}
int main()
{
int n;
cin >> n;
NODE *head = build(n);
sort(head);
return 0;
}
这题我做麻烦了。。。其实完全用不着链表的,用一个NODE array[]存所有的节点然后排个序OK。万恶的惯性思维。。。
PATbasic1004
最新推荐文章于 2023-03-06 11:37:33 发布
3071

被折叠的 条评论
为什么被折叠?



