PS
BOJ 32748 : f(A + B)
lickelon
2024. 12. 23. 23:43
- 문제 링크 : boj.kr/32748
- 난이도 : S5
- 태그 : 구현, 문자열
코드
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define INF 0x7FFFFFFF
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
map<int, int> f, r;
for(int i = 0; i < 10; i++) {
int input;
cin >> input;
f[i] = input;
r[input] = i;
}
string a, b;
cin >> a >> b;
for(auto &e : a) e = r[e-'0']+'0';
for(auto &e : b) e = r[e-'0']+'0';
int sum = stoi(a)+stoi(b);
string ss = to_string(sum);
for(auto &e : ss) e = f[e-'0']+'0';
cout << ss;
return 0;
}
풀이
함수와 역함수를 map으로 구현한다.
정수형과 문자열을 바꿔가며 구현하면 된다.
728x90