250x250
반응형
Notice
Recent Posts
Recent Comments
Link
N
(프로그래머스 c++)없는 숫자 더하기 본문
728x90
반응형
https://programmers.co.kr/learn/courses/30/lessons/86051
코딩테스트 연습 - 없는 숫자 더하기
0부터 9까지의 숫자 중 일부가 들어있는 배열 numbers가 매개변수로 주어집니다. numbers에서 찾을 수 없는 0부터 9까지의 숫자를 모두 찾아 더한 수를 return 하도록 solution 함수를 완성해주세요. 제한
programmers.co.kr
0 ~ 9의 숫자의 총합은 45다.
numbers 벡터에서 없는 숫자의 총합이기 때문에,
numbers의 원소를 빼면 답이다.
#include <string>
#include <vector>
using namespace std;
int solution(vector<int> numbers) {
int answer = 45;
for(int i = 0; i < numbers.size(); i++){
answer -= numbers[i];
}
return answer;
}728x90
반응형
'프로그래머스 알고리즘 > 0 & 1단계' 카테고리의 다른 글
| (프로그래머스 c++) 이차원 배열 대각선 순회하기 (1) | 2025.07.24 |
|---|---|
| (프로그래머스 C++) 공백으로 구분하기2 (0) | 2025.07.24 |
| (프로그래머스 c++)예산 (0) | 2021.09.28 |
| (프로그래머스 c++)약수의 개수와 덧셈 (0) | 2021.06.08 |
| (프로그래머스 c++)음양 더하기 (0) | 2021.05.06 |