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<sstream> | |
#include<vector> | |
using namespace std; | |
void swap(string & arr ,int a, int b){ | |
int temp = arr[a]; | |
arr[a] = arr[b]; | |
arr[b] = temp; | |
} | |
void sortThree(string & arr, int front, int mid, int rear){ | |
if (arr[front] > arr[mid]) swap(arr,front,mid); | |
if (arr[front] > arr[rear]) swap(arr,front,rear); | |
if (arr[mid] > arr[rear]) swap(arr,mid,rear); | |
} | |
void median_of_qsort(string &arr, int front, int rear){ | |
int i,j, pivot, mid = front + (rear - front)/2; | |
sortThree(arr, front, mid, rear); | |
if (rear - front + 1 > 3){ | |
pivot = arr[mid]; | |
swap(arr,mid,rear-1); | |
i = front; | |
j = rear - 1; | |
while (true){ | |
while (arr[++i]<pivot && i < rear); | |
while (arr[--j]>pivot && j > front); | |
if (i >= j) break; | |
swap(arr,i,j); | |
} | |
swap(arr, i, rear-1); | |
median_of_qsort(arr,front, i-1); | |
median_of_qsort(arr, i+1, rear); | |
} | |
} | |
int main(void) | |
{ | |
int N; | |
cin >> N; | |
vector<pair<char,int>> vec; | |
for (int i=0;i<N;i++) | |
{ | |
string input; | |
cin >> input; | |
bool find = false; | |
for (int j=0;j<vec.size();j++) | |
{ | |
if (input[0] == vec[j].first) | |
{ | |
vec[j].second+=1; | |
find = true; | |
break; | |
} | |
} | |
if (find == false) | |
vec.push_back(make_pair(input[0], 1)); | |
} | |
bool find = false; | |
string result=""; | |
for (int i=0;i<vec.size();i++) | |
{ | |
if (vec[i].second >= 5) | |
{ | |
result+=vec[i].first; | |
find = true; | |
} | |
} | |
if (find == true) | |
{ | |
median_of_qsort(result, 0, result.length()-1); | |
cout << result; | |
} | |
if (find == false) | |
cout << "PREDAJA"; | |
} |
댓글
댓글 쓰기