프로그래머스 120851 숨어있는 숫자의 덧셈 (1)

1 개요[ | ]

프로그래머스 120851 숨어있는 숫자의 덧셈 (1)

2 C++[ | ]

#include <string>
#include <vector>

using namespace std;

int solution(string my_string) {
    int answer = 0;
    int num;
    for(auto& ch: my_string) {
        if(ch < '0' || ch > '9') {
            continue;
        }
        num = ch - '0';
        answer += num;
    }
    return answer;
}
#include <string>
#include <vector>

using namespace std;

int solution(string my_string) {
    int answer = 0;
    for(auto& ch: my_string) {
        if(isdigit(ch)) {
            answer +=  ch - '0';
        }
    }
    return answer;
}