Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 투 포인터
- 알고리즘
- 트리
- 우선순위 큐
- 브루트포스
- VR
- DFS
- Team Fortress 2
- 시뮬레이션
- 그리디 알고리즘
- BFS
- 다익스트라
- 자료구조
- XR Interaction Toolkit
- 구현
- 문자열
- 누적 합
- 유니온 파인드
- 다이나믹 프로그래밍
- 유니티
- 수학
- c++
- 그래프
- ue5
- 백준
- 스택
- Unreal Engine 5
- 백트래킹
- 재귀
- 정렬
Archives
- Today
- Total
1일1알
백준 1431번 시리얼 번호 C++ 본문
https://www.acmicpc.net/problem/1431
1431번: 시리얼 번호
첫째 줄에 기타의 개수 N이 주어진다. N은 50보다 작거나 같다. 둘째 줄부터 N개의 줄에 시리얼 번호가 하나씩 주어진다. 시리얼 번호의 길이는 최대 50이고, 알파벳 대문자 또는 숫자로만 이루어
www.acmicpc.net
MyStr 구조체에 비교연산자 재정의
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <limits.h>
using namespace std;
using int64 = long long;
struct MyStr {
string str;
bool operator<(const MyStr& other) const {
if (str.length() == other.str.length()) {
int mySum = 0;
int otherSum = 0;
for (int i = 0; i < str.length(); i++) {
if (str[i] >= '0' && str[i] <= '9') {
mySum += str[i] - '0';
}
if (other.str[i] >= '0' && other.str[i] <= '9') {
otherSum += other.str[i] - '0';
}
}
if (mySum == otherSum) {
return str < other.str;
}
return mySum < otherSum;
}
return str.length() < other.str.length();
}
};
vector<MyStr> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
string str;
cin >> str;
v.push_back({str});
}
sort(v.begin(), v.end());
for (auto a : v) {
cout << a.str << "\n";
}
};
'알고리즘' 카테고리의 다른 글
백준 3187번 양치기 꿍 C++ (0) | 2023.06.29 |
---|---|
백준 16507번 어두운 건 무서워 C++ (0) | 2023.06.22 |
백준 12101번 1, 2, 3 더하기 2 C++ (0) | 2023.06.10 |
백준 17610번 양팔저울 C++ (0) | 2023.06.09 |
백준 21278번 호석이 두 마리 치킨 C++ (1) | 2023.06.08 |