PS/BOJ

[백준 BOJ] 2864 5와 6의 차이

Jubil 2018. 11. 9. 17:49
반응형

2864_5 6의 차이

링크

https://www.acmicpc.net/problem/2864

 

풀이


 

모든 6 5로 헷갈렸을 때 최솟값을, 모든 5 6으로 헷갈렸을 때 최댓값을 갖습니다. A B가 양수이기 때문이죠. 문자열 변환만 잘 처리해주면 됩니다.

 

코드

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

31

32

33

34

//2864_5 6 차이

#include <iostream>

#include <string>

using namespace std;

 

string str1, str2;

string str1to5, str2to5;

string str1to6, str2to6;

 

int main() {

    cin >> str1 >> str2;

 

    for (int i = 0; i < str1.length(); ++i) {    //str1 변환

        string tmp;

        tmp = str1[i];

        if (tmp == "6") tmp = "5";

        str1to5.append(tmp);

        if (tmp == "5") tmp = "6";

        str1to6.append(tmp);

    }

 

    for (int i = 0; i < str2.length(); ++i) {    //str2 변환

        string tmp;

        tmp = str2[i];

        if (tmp == "6") tmp = "5";

        str2to5.append(tmp);

        if (tmp == "5") tmp = "6";

        str2to6.append(tmp);

    }

 

    cout << atoi(str1to5.c_str()) + atoi(str2to5.c_str()) << " " << atoi(str1to6.c_str()) + atoi(str2to6.c_str()) << endl;

 

    return 0;

}

Colored by Color Scripter

cs

 



반응형

'PS > BOJ' 카테고리의 다른 글

[백준 BOJ] 1629 곱셈  (0) 2018.11.11
[백준 BOJ] 1964 오각형, 오각형, 오각형...  (0) 2018.11.10
[백준 BOJ] 1100 하얀 칸  (0) 2018.11.08
[백준 BOJ] 1076 저항  (0) 2018.11.05
[백준 BOJ] 1075 나누기  (0) 2018.11.04