-
[BOJ]1431 - Sort 본문
https://www.acmicpc.net/problem/1431
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
struct info {
int sum;
string str;
};
vector<info> v;
bool F(info a, info b) {
if (a.str.length() != b.str.length()) {
return a.str.length() < b.str.length();
}
else {
if (a.sum != b.sum)
return a.sum < b.sum;
else
return a.str < b.str;
}
}
int cal(info a) {
int i = 0;
int sum = 0;
while (i < a.str.length()) {
string tmp = "";
if (a.str[i] >= '0' && a.str[i] <= '9') {
tmp = a.str[i];
}
sum += atoi(tmp.c_str());
i++;
}
return sum;
}
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
info str;
cin >> str.str;
str.sum = cal(str);
v.push_back(str);
}
sort(v.begin(), v.end(), F);
for (int i = 0; i < N; i++) {
cout << v[i].str << endl;
}
return 0;
}
'Algorithm > Baekjoon' 카테고리의 다른 글
[BOJ]10814-Sort (0) | 2020.03.12 |
---|---|
[BOJ]10825 (0) | 2020.03.10 |
[BOJ]11004 - 퀵소트/퀵셀렉션/머지소트 (0) | 2020.03.09 |
[BOJ]2136_DFS (0) | 2019.07.10 |
1890 점프 (0) | 2018.02.12 |
Comments