웅재의 코딩세상

[프로그래머스] 9로 나눈 나머지 본문

코딩테스트/프로그래머스 - LV 0

[프로그래머스] 9로 나눈 나머지

웅드 2024. 1. 30. 15:44

 

 

  • 풀이
#include <string>
#include <vector>

using namespace std;

int solution(string number) {
    int answer = 0;
    for(int i=0; i<number.size(); i++){
        answer += number[i]-'0';
    }

    return answer % 9;
}
반응형