https://www.acmicpc.net/problem/11170
11170번: 0의 개수
N부터 M까지의 수들을 종이에 적었을 때 종이에 적힌 0들을 세는 프로그램을 작성하라. 예를 들어, N, M이 각각 0, 10일 때 0을 세면 0에 하나, 10에 하나가 있으므로 답은 2이다.
www.acmicpc.net
//[C++] 백준 문제풀이 (Implementation)
#include <bits/stdc++.h>
int solve(int num){
if (num == 0) return 1;
int cnt = 0;
while(num != 0){
if (num % 10 == 0) ++cnt;
num /= 10;
}
return cnt;
}
int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int t;
std::cin >> t;
int n, m;
while(t--){
int sum = 0;
std::cin >> n >> m;
for (int i = n; i <= m; ++i){
sum += solve(i);
}
std::cout << sum << "\n";
}
return 0;
}
'백준 문제풀이 > Implementation' 카테고리의 다른 글
C++] 백준 문제풀이 (Implementation) 1051 숫자 정사각형 (0) | 2023.06.27 |
---|---|
[C++] 백준 문제풀이 (Implementation) 10829 이진수 변환 (0) | 2023.06.26 |
[C++] 백준 문제풀이 (Implementation) 5586 JOI와 IOI (0) | 2023.06.26 |
[C++] 백준 문제풀이 (Implementation) 2511번 카드놀이 (0) | 2023.06.26 |
[C++] 백준 문제풀이 (Implementation) 1568번 새 (0) | 2023.06.26 |