#include <iostream>
#include <cstring>
using namespace std;
struct Node
{
char m_cName[20];
int m_iHp;
int m_iMp;
int m_iSpeed;
int m_iRange;
char m_cPosition[20];
Node* next;
};
//////////////////
// 함수 //
//////////////////
int Menu();
void InputData();
void Insert( char* name, int hp, int mp, int speed, int range, char* position );
void PrintAll();
void Search();
void Delete();
void PositionDeleteAll();
void FindMaxHp();
void SortByHp();
//////////////////
// 변수 //
//////////////////
Node *head = NULL;
char inputName[20];
int inputHp;
int inputMp;
int inputSpeed;
int inputRange;
char inputPosition[20];
int maxHp;
int sortFlag;
//////////////////
// 메인 //
//////////////////
int main()
{
Insert("럭스", 477, 334, 330, 550, "mid");
Insert("베이가", 492, 342, 340, 525, "mid");
Insert("벨코즈", 507, 325, 340, 525, "bottom");
Insert("징크스", 517, 245, 325, 525, "bottom");
Insert("오리아나", 517, 334, 325, 525, "mid");
Insert("트위치", 525, 287, 330, 550, "jungle");
Insert("앨리스", 529, 324, 335, 550, "jungle");
Insert("바드", 535, 350, 330, 500, "bottom");
Insert("코그모", 546, 322, 325, 500, "bottom");
Insert("룰루", 552, 292, 325, 550, "suppot");
Insert("모데카이저", 555, 120, 340, 120, "mid");
Insert("드레이븐", 557, 310, 330, 550, "bottom");
Insert("자르반4세", 571, 302, 340, 175, "jungle");
Insert("케일", 574, 322, 335, 125, "top");
Insert("블리츠크랭크", 582, 267, 325, 125, "suppot");
Insert("문도박사", 582, 0, 345, 125, "top");
Insert("다이애나", 589, 297, 345, 150, "mid");
Insert("워윅", 592, 240, 345, 125, "jungle");
Insert("잭스", 592, 288, 350, 125, "top");
Insert("트린다미어", 625, 100, 345, 125, "top");
Insert("갱플랭크", 631, 282, 345, 125, "top");
while ( 1 )
{
switch ( Menu() )
{
case 1 :
Search();
break;
case 2 :
InputData();
Insert(::inputName, ::inputHp, ::inputMp, ::inputSpeed, ::inputRange, ::inputPosition);
break;
case 3 :
Delete();
break;
case 4 :
PositionDeleteAll();
break;
case 5 :
PrintAll();
break;
case 6 :
FindMaxHp();
break;
case 7 :
SortByHp();
break;
default :
break;
}
}
}
int Menu()
{
int num;
cout << "--------------Menu---------------" << endl;
cout << "1. 챔피언 Search" << endl;
cout << "2. 챔피언 Insert" << endl;
cout << "3. 챔피언 Delete" << endl;
cout << "4. Position DeleteAll" << endl;
cout << "5. PrintAll" << endl;
cout << "6. FindMaxHp" << endl;
cout << "7. SortByHp" << endl;
cout << "----------------------------------" << endl;
cout << "메뉴를 입력하세요 [ 1 ~ 7 ] : ";
cin >> num;
if ( 0 < num && num < 8)
return num;
}
void Insert(char* name, int hp, int mp, int speed, int range, char* position)
{
Node* temp = head;
if ( temp != NULL && temp->next != head ){
while ( temp->next != head)
temp = temp->next;
temp->next = new Node;
temp = temp->next;
temp->next = head;
temp->m_iHp = hp;
temp->m_iMp = mp;
temp->m_iSpeed = speed;
temp->m_iRange = range;
strcpy(temp->m_cName, name);
strcpy(temp->m_cPosition, position);
}
else if (head == NULL){
head = new Node;
head->next = head;
head->m_iHp = hp;
head->m_iMp = mp;
head->m_iSpeed = speed;
head->m_iRange = range;
strcpy(head->m_cName, name);
strcpy(head->m_cPosition, position);
}
else if ( temp->next == temp){
temp->next = new Node;
temp->next->next = head;
temp->next->m_iHp = hp;
temp->next->m_iMp = mp;
temp->next->m_iSpeed = speed;
temp->next->m_iRange = range;
strcpy(temp->next->m_cName, name);
strcpy(temp->next->m_cPosition, position);
}
}
void PrintAll()
{
Node *temp = head;
if ( head != NULL && (
!strcmp(temp->m_cPosition, "jungle") ||
!strcmp(temp->m_cPosition, "suppot") ||
!strcmp(temp->m_cPosition, "bottom") ||
!strcmp(temp->m_cPosition, "mid") ||
!strcmp(temp->m_cPosition, "top")) ){
while (temp->next != head)
{
cout << "이름 : " << temp->m_cName << endl;
cout << "체력 : " << temp->m_iHp << endl;
cout << "마력 : " << temp->m_iMp << endl;
cout << "속도 : " << temp->m_iSpeed << endl;
cout << "범위 : " << temp->m_iRange << endl;
cout << "포지션 : " << temp->m_cPosition << endl;
temp = temp->next;
}
cout << "이름 : " << temp->m_cName << endl;
cout << "체력 : " << temp->m_iHp << endl;
cout << "마력 : " << temp->m_iMp << endl;
cout << "속도 : " << temp->m_iSpeed << endl;
cout << "범위 : " << temp->m_iRange << endl;
cout << "포지션 : " << temp->m_cPosition << endl;
}
}
void Search()
{
Node* temp = head;
char name[20] = "NULL";
cout << "검색할 챔피언의 이름을 입력해주세요 : ";
cin >> name;
while ( temp->next != head){
if ( !strcmp(name, temp->m_cName) ){
cout << "이름 : " << temp->m_cName << endl;
cout << "체력 : " << temp->m_iHp << endl;
cout << "마력 : " << temp->m_iMp << endl;
cout << "속도 : " << temp->m_iSpeed << endl;
cout << "범위 : " << temp->m_iRange << endl;
cout << "포지션 : " << temp->m_cPosition << endl;
}
temp = temp->next;
}
if ( !strcmp(name, temp->m_cName) ){
cout << "이름 : " << temp->m_cName << endl;
cout << "체력 : " << temp->m_iHp << endl;
cout << "마력 : " << temp->m_iMp << endl;
cout << "속도 : " << temp->m_iSpeed << endl;
cout << "범위 : " << temp->m_iRange << endl;
cout << "포지션 : " << temp->m_cPosition << endl;
}
}
void Delete()
{
Node* temp = head;
Node* p = NULL;
char name[20] = "NULL";
cout << "삭제할 챔피언의 이름을 입력해주세요 : ";
cin >> name;
while ( temp->next != head){
if ( !strcmp(name, temp->next->m_cName) ){
p = temp->next;
temp->next = temp->next->next;
p->next = nullptr;
delete p;
}
else
temp = temp->next;
}
if ( !strcmp(name, head->m_cName) ){
p = head;
p = head->next;
delete head;
head = p;
temp->next= head;
}
}
void PositionDeleteAll()
{
Node* temp = head;
Node* p = NULL;
char position[20] = "NULL";
cout << "삭제할 Position을 입력해주세요 : ";
cin >> position;
while ( temp->next != head){
if ( !strcmp(position, temp->next->m_cPosition) ){
p = temp->next;
temp->next = temp->next->next;
p->next = nullptr;
delete p;
}
else
temp = temp->next;
}
if ( !strcmp(position, head->m_cPosition) ){
p = head;
p = head->next;
delete head;
head = p;
temp->next= head;
}
};
void InputData()
{
cout << "이름을 입력하세요: ";
cin >> ::inputName;
cout << "체력을 입력하세요: ";
cin >> ::inputHp;
cout << "마력을 입력하세요: ";
cin >> ::inputMp;
cout <<"속도 입력하세요: ";
cin >> ::inputSpeed;
cout << "범위를 입력하세요: ";
cin >> ::inputRange;
cout << "포지션을 입력하세요: ";
cin >> ::inputPosition;
}
void FindMaxHp()
{
Node* temp = head;
if ( head->m_iHp > maxHp)
maxHp = head->m_iHp;
while(temp->next != head)
{
if ( temp->m_iHp > maxHp)
maxHp = temp->m_iHp;
temp = temp->next;
}
if (temp->m_iHp > maxHp)
maxHp = temp->m_iHp;
cout << "가장 높은 체력 : ";
cout << maxHp << endl;
temp = head;
if ( head->m_iHp == maxHp){
cout << "이름 : " << head->m_cName << endl;
cout << "체력 : " << head->m_iHp << endl;
cout << "마력 : " << head->m_iMp << endl;
cout << "속도 : " << head->m_iSpeed << endl;
cout << "범위 : " << head->m_iRange << endl;
cout << "포지션 : " << head->m_cPosition << endl;
}
while(temp->next != head)
{
if ( temp->m_iHp == maxHp){
cout << "이름 : " << temp->m_cName << endl;
cout << "체력 : " << temp->m_iHp << endl;
cout << "마력 : " << temp->m_iMp << endl;
cout << "속도 : " << temp->m_iSpeed << endl;
cout << "범위 : " << temp->m_iRange << endl;
cout << "포지션 : " << temp->m_cPosition << endl;
}
temp = temp->next;
}
if (temp->m_iHp == maxHp){
cout << "이름 : " << temp->m_cName << endl;
cout << "체력 : " << temp->m_iHp << endl;
cout << "마력 : " << temp->m_iMp << endl;
cout << "속도 : " << temp->m_iSpeed << endl;
cout << "범위 : " << temp->m_iRange << endl;
cout << "포지션 : " << temp->m_cPosition << endl;
}
::maxHp = 0;
}
void SortByHp()
{
Node* temp = head;
Node* rotate = head;
Node* whileNode = head;
Node* remember = nullptr;
Node* prv = nullptr;
while(temp->next!= head){
if( temp->m_iHp > temp->next->m_iHp){
if ( temp == head){
if ( temp->next->next != head){
rotate = head;
while(rotate->next != head)
rotate = rotate->next;
remember = temp->next;
temp->next = temp->next->next;
remember->next = temp;
head = remember;
rotate->next = head;
temp = head;
}
else if ( temp->next->next == head){
remember = temp->next;
temp->next = temp->next->next;
remember->next = temp;
head = remember;
temp->next->next = head;
temp = head;
}
}
else if ( temp->next->next != head){
rotate = head;
while(rotate->next != temp){
rotate = rotate->next;
}
prv = rotate;
remember = temp->next;
temp->next = temp->next->next;
remember->next = temp;
prv->next = remember;
temp = head;
}
else if ( temp->next->next == head){
rotate = head;
while(rotate->next != temp){
rotate = rotate->next;
}
prv = rotate;
remember = temp->next;
temp->next = temp->next->next;
remember->next = temp;
prv->next = remember;
temp->next = head;
temp = head;
}
}
temp = temp->next;
}
sortFlag = 1;
}



















'프로그래밍 > C++언어' 카테고리의 다른 글

[ 기술면접 정리 서버 / C++ ]  (0) 2019.03.06

+ Recent posts