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
- 정석학술정보관
- 컴퓨터공학과
- Operating System
- 자료구조
- 코딩
- 스택
- 코테
- 너비우선탐색
- 컴공
- cs
- Computer science
- 알고리즘
- 그래프
- 정석
- OS
- 문제풀이
- 백준
- bfs
- Stack
- 북리뷰
- 브루트포스
- 구현
- c++
- 컴공과
- coding
- 오퍼레이팅시스템
- 개발
- 오에스
- vector
- DP
Archives
- Today
- Total
Little Jay
[C++] 백준 15312번 - 이름 궁합 본문
ascii 코드를 이용해서 잘 변환시키는게 중요했던 문제
처음에 알파벳 변환은 'A'의 아스키 값인 65를 빼주면 되고,
숫자를 임시적으로 문자열로 저장했을 때,
이를 다시 숫자로 변환할때는 0의 아스키 값인 48을 빼주면 된다.
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int alphabet[] = { 3, 2, 1, 2, 3, 3, 2, 3, 3, 2, 2, 1, 2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1 };
string s1, s2;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin >> s1;
cin >> s2;
string temp_str;
// char - 65 하면 index번호 나온다
for (int i = 0; i < s1.size(); i++) {
int temp = alphabet[(s1[i] - 65)];
temp_str += to_string(temp);
temp = alphabet[(s2[i] - 65)];
temp_str += to_string(temp);
}
while(temp_str.size() > 2) {
string s;
// char to int => char - 48
for (int i = 0; i < temp_str.size() - 1; i++) {
int temp = ((temp_str[i] - 48) + (temp_str[i+1] - 48)) % 10;
s += to_string(temp);
}
temp_str = s;
}
cout << temp_str << endl;
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 6588번 - 골드바흐 추측 (0) | 2022.02.11 |
---|---|
[C++] 백준 1744번 - 수 묶기 (0) | 2022.02.11 |
[C++] 백준 13303번 - 타일 장식물 (0) | 2022.02.06 |
[C++] 백준 7662번 - 이중 우선순위 큐(multiset) (0) | 2022.01.13 |
[C++] 백준 1302번 - 베스트셀러 (0) | 2022.01.11 |
Comments