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 |
Tags
- Unreal Engine 5
- 다이나믹 프로그래밍
- XR Interaction Toolkit
- ue5
- 스택
- 유니온 파인드
- 문자열
- 유니티
- 백준
- 구현
- DFS
- 우선순위 큐
- 알고리즘
- 투 포인터
- 정렬
- 자료구조
- 재귀
- 다익스트라
- 누적 합
- 수학
- 브루트포스
- 백트래킹
- VR
- 트리
- BFS
- 시뮬레이션
- Team Fortress 2
- 그리디 알고리즘
- c++
- 그래프
Archives
- Today
- Total
1일1알
백준 1339번 단어 수학 C++ 본문
알파벳이 앞에 나올수록 가산점을 더 부여해서 알파벳의 개수를 저장하고 저장한 알파벳의 개수가 많은 순서대로 숫자를 할당하였다.
예를들어 AA, BC 가 있다면 A는 10 + 1 = 11, B는 10, C는 1이 되고 A에 9, B에 8, C에 7을 할당한다.
만약 알파벳의 길이가 다르다면 가장 긴 알파벳의 개수를 기준으로 짧은 알파벳 앞에 @를 더해서 건너뛰도록 하였다.
예를들어 ABC, DE가 있다면 DE앞에 @를 붙여 @DE로 만들어서 길이를 맞춰주고 @인 경우는 연산을 하지 않도록 했다.
#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;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<string> strs(n);
int maxLength = 0;
for (int i = 0; i < n; i++) {
cin >> strs[i];
maxLength = max(maxLength, int(strs[i].length()));
}
for (int i = 0; i < n; i++) {
int currLength = strs[i].length();
for (int j = 0; j < maxLength - currLength; j++) {
strs[i] = "@" + strs[i];
}
}
int num = 9;
int ans = 0;
map<char, int> mp;
multimap<int, char, greater<int>> mmp;
for (int i = 0; i < maxLength; i++) {
int mul = pow(10, maxLength - i - 1);
for (int j = 0; j < n; j++) {
if (strs[j][i] == '@') continue;
mp[strs[j][i]] += mul;
}
}
for (auto a : mp) {
mmp.insert({ a.second,a.first });
}
for (auto a : mmp) {
ans += a.first * num;
num--;
}
cout << ans;
}
'알고리즘' 카테고리의 다른 글
백준 5052번 전화번호 목록 C++ (0) | 2022.08.14 |
---|---|
백준 14402번 가장 긴 증가하는 부분 수열 4 C++ (0) | 2022.08.13 |
백준 1261번 알고스팟 C++ (0) | 2022.08.11 |
백준 3055번 탈출 C++ (0) | 2022.08.10 |
백준 1922번 네트워크 연결 C++ (0) | 2022.08.09 |