Skip to content

Instantly share code, notes, and snippets.

@pezy
Last active August 29, 2015 14:08
Show Gist options
  • Save pezy/2bbdf4073351ddb06a1b to your computer and use it in GitHub Desktop.
Save pezy/2bbdf4073351ddb06a1b to your computer and use it in GitHub Desktop.
//
// main.cpp
// Test
//
// Created by pezy on 9/11/14.
// Copyright (c) 2014 PEZY. All rights reserved.
//
#include<iostream>
using namespace std;
struct member{
char name[4];
int year;
int month;
member *next;
};
void Insert(member* &pHead, member* &pNode){
if(pHead == NULL){
pHead = pNode;
return;
}
if(pNode->year < pHead->year || (pNode->year == pHead->year && pNode->month < pHead->month)){
pNode->next = pHead;
pHead = pNode;
return;
}
member *p = pHead;
member *q = p->next;
while(q != NULL){
if(pNode->year < q->year || (pNode->year == q->year && pNode->month < q->month)) {
pNode->next = q;
p->next = pNode;
return;
}
p = q;
q = q->next;
}
p->next = pNode;
}
void Input(member* &head){
member *pNode = new member;
pNode->next = NULL;
cin >> pNode->name >> pNode->year >> pNode->month;
Insert(head, pNode);
return;
}
void Output(member* head){
member *p = head;
for(int i = 0; i < 7; i++) {
cout << p->name <<" "<< p->year <<"."<< p->month <<endl;
p = p->next;
}
}
int main(){
member *head = NULL;
for(int i = 0; i < 7; i++)
Input(head);
Output(head);
system("pause");
return 0;
}
#include <iostream>
#include <string>
#include <set>
class Member
{
public:
Member(){}
friend std::istream& operator>>(std::istream& in, Member& m) { in >> m.name >> m.bYear >> m.bMonth; return in; }
friend std::ostream& operator<<(std::ostream& out, const Member& m) { out << m.name << " " << m.bYear << "." << m.bMonth; return out; }
bool operator<(const Member& m) const { return bYear < m.bYear || (bYear == m.bYear && bMonth < m.bMonth);}
private:
std::string name;
int bYear;
int bMonth;
};
int main()
{
std::set<Member> s;
for (int i=0; i!=7; ++i)
{
Member m;
std::cin >> m;
s.insert(m);
}
for (auto m : s)
std::cout << m << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment