#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
bool cmp(string a, string b) {
if (a.length() != b.length()) return a.length() < b.length(); //๊ธธ์ด๊ฐ ๋ค๋ฅธ๊ฒฝ์ฐ ์งง์ ๊ฒ ๋ถํฐ ๋์ด
else { //๊ธธ์ด๊ฐ ๊ฐ์๊ฒฝ์ฐ
int sumA=0,sumB= 0;
for (int i = 0; i <a.length(); i++) {
if (a[i] - '0' >= 0 && a[i] - '0' <= 9) sumA += a[i] - '0';
if (b[i] - '0' >= 0 && b[i] - '0' <= 9) sumB += b[i] - '0';
}
if (sumA != sumB) return sumA < sumB; // ํฉ์ด ์์๊ฒ ์์ผ๋ก
else return a < b; //ํฉ์ด ๊ฐ์๊ฒฝ์ฐ ์ฌ์ ์์ผ๋ก
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N; cin >> N;
vector<string>v;
while (N--) {
string s; cin >> s;
v.push_back(s);
}
sort(v.begin(), v.end(), cmp);
for (string s : v) {
cout << s << "\n";
}
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 14467๋ฒ - ์๊ฐ ๊ธธ์ ๊ฑด๋๊ฐ ์ด์ 1 (0) | 2021.11.07 |
---|---|
[๋ฐฑ์ค,c++] 14425๋ฒ - ๋ฌธ์์ด ์งํฉ (0) | 2021.11.07 |
[๋ฐฑ์ค,c++] 14391๋ฒ - ์ข ์ด ์กฐ๊ฐ (0) | 2021.11.07 |
[๋ฐฑ์ค,c++] 14284๋ฒ - ๊ฐ์ ์ด์ด๊ฐ๊ธฐ2 (0) | 2021.11.06 |
[๋ฐฑ์ค,c++] 1427๋ฒ - ์ํธ์ธ์ฌ์ด๋ (0) | 2021.11.06 |
[๋ฐฑ์ค,c++] 14241๋ฒ - ์ฌ๋ผ์ ํฉ์น๊ธฐ (0) | 2021.11.06 |
๋๊ธ