MarkSon
-
백준 11720번 _ C++ 입출력소프트웨어전공/알고리즘 문제풀이 2021. 9. 21. 13:48
문제를 보고 우선 배열을 떠올렸다. 숫자가 공백없이 쓰여있고, 배열의 각 인덱스에 숫자를 차례대로 넣은 다음 배열의 요소를 모두 더해서 출력하면 될것이라 생각 그러나, 배열로는 결국 구현하지 못했다..! 구글링으로 여러 코드를 참조했는데, 풀이 방법은 다양했다. 1. 아스키 코드를 활용해서 푸는 법 입출력 문제에서 계속 헤매는 이유가 cin을 잘 몰라서 그렇다고 생각한다 아스키 코드를 써서 풀어도 되겠다는 생각은 했었지만, char에 N번만큼 값을 하나하나 담는다는것? 아직 이해가 완벽하게 안된다. -> char에는 단 하나의 문자만 담기니까, 12345라는 입력에는 1/2/3/4/5 이렇게 공간이 할당될 것이다. 2. 배열을 활용해서 푸는 법 내가 처음 문제를 풀때 떠올린 방법과 유사하다.