[백준] 5648번 역원소 정렬 (C++, 정렬)
728x90
반응형
예제를 보고 알아서 정렬 조건을 만들어줘야 된다.
0을 없애기 위해 문자열을 정수로 변환한 후 다시 문자열로 만들어줬다
#define _CRT_SECURE_NO_WARNINGS
#define rep(i,s,e) for(int i=s;i<e;i++)
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int cmp(const string& a, const string& b) {
if (a.length() != b.length())return a.length() < b.length();
return stol(a) < stol(b);
}
int main(int argc, char** argv)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
vector<string> a;
string tmp;
cin >> n;
rep(i, 0, n) {
cin >> tmp;
reverse(tmp.begin(), tmp.end());
a.push_back(to_string(stol(tmp)));
}
sort(a.begin(),a.end(),cmp);
for (auto x : a) {
cout << stol(x) << "\n";
}
return 0;
}
728x90
반응형
'백준' 카테고리의 다른 글
[백준] 7795번 먹을 것인가 먹힐 것인가 (C++, 정렬 혹은 이분탐색) (0) | 2021.10.08 |
---|---|
[백준] 10825번 국영수 (C++ , 정렬) (0) | 2021.10.07 |
[백준] 11652번 카드 (C++, 정렬) (0) | 2021.10.07 |
[백준] 1431번 시리얼 번호 (C++, 정렬) (0) | 2021.10.07 |
[백준] 17219번 비밀번호 찾기 (C++, 해시) (0) | 2021.10.06 |
TAGS.