https://www.acmicpc.net/problem/11536
11536번: 줄 세우기
이름이 증가하는 순으로 나타나면 INCREASING, 감소하는 순이면 DECREASING을 한 줄에 출력한다. 만약 위의 두 경우가 아니라면 NEITHER를 출력한다.
www.acmicpc.net
간단한 문제 !
temp 2개를 생성, 오름차순/내림차순 각 정렬을 하고
입력된 순서와 비교
#include <bits/stdc++.h>
using namespace std;
int n;
vector<string> vec;
vector<string> temp1;
vector<string> temp2;
bool compare(string s1, string s2){
return s1 > s2;
}
int main(void){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n;
for(int i=0; i<n; i++){
string str;
cin>>str;
vec.push_back(str);
}
for(int i=0; i<n; i++){
temp1.push_back(vec[i]);
temp2.push_back(vec[i]);
}
sort(temp1.begin(), temp1.end());
sort(temp2.begin(),temp2.end(),compare);
if(vec == temp1){
cout<<"INCREASING"<<'\n';
}
else if( vec == temp2){
cout<<"DECREASING"<<'\n';
}
else {
cout<<"NEITHER"<<'\n';
}
}
'Algorithm > BOJ' 카테고리의 다른 글
[c++] 백준 1149 RGB 거리 (0) | 2021.01.05 |
---|---|
[c++] 백준 2597 계단오르기 (0) | 2021.01.05 |
[c++] 백준 10825 국영수 (0) | 2021.01.04 |
[c++] 백준 11656 접미사 배열 (0) | 2021.01.04 |
[c++] 백준 1181 단어 정렬 (0) | 2021.01.04 |