728x90
문자로 입력 받은 후
5를 6으로 해서 string에 저장하고
6을 5로 해서 다른 string에 저장합니다.
최소값을 구할때는 6을 5로 한 string끼리 더하고
최대값을 구할때는 5를 6으로 한 string끼리 더합니다.
string을 int로 바꿀때는 stoi 함수를 사용했고
int를 string으로 바꿀때는 to_string함수를 사용했습니다.
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
int temp;
string s1;
string s2;
string sMin;
string sMax;
cin >> s1;
cin >> s2;
string s1Min = s1;
string s1Max = s1;
string s2Min = s2;
string s2Max = s2;
for (int i = 0; i < s1.length(); ++i) {
if (s1[i]- '0' == 5) {
s1Max[i] = '6';
}
if (s1[i] - '0' == 6) {
s1Min[i] = '5';
}
if (s2[i] - '0' == 5) {
s2Max[i] = '6';
}
if (s2[i] - '0' == 6) {
s2Min[i] = '5';
}
}
temp = stoi(s1Min) + stoi(s2Min);
sMin = to_string(temp);
temp = stoi(s1Max) + stoi(s2Max);
sMax = to_string(temp);
cout << sMin << " ";
cout << sMax << endl;
return 0;
}
'알고리즘' 카테고리의 다른 글
[C++] 백준 10826번 피보나치 수 4 (0) | 2019.09.12 |
---|---|
[C++] 백준 10987번 모음의 개수 (0) | 2019.09.12 |
[C++] 백준 11656번 접미사 배열 (0) | 2019.09.12 |
[C++] 백준 10988번 팰린드롬인지 확인하기 (0) | 2019.09.12 |
[C++] 백준 15353번 큰 수 A+B (2) (0) | 2019.09.12 |