Last active
August 29, 2015 14:08
-
-
Save pezy/2bbdf4073351ddb06a1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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