Little Jay

[C++] 백준 14912번 숫자 빈도수 본문

알고리즘/BOJ

[C++] 백준 14912번 숫자 빈도수

Jay, Lee 2021. 3. 25. 15:19
#include <iostream>
#include <string>
using namespace std;

int main() {

	int n;
	char digit;
	cin >> n >> digit;
	int repeated = 0;

	for (int i = 0; i < n; i++) {
		string num = to_string(i + 1);
		for (int k = 0; k < num.length(); k++) {
			if (num[k] == digit)
				repeated++;
		}
	}
	
	cout << repeated << "\n";

	return 0;
}

'알고리즘 > BOJ' 카테고리의 다른 글

[C++] 백준 11650번 좌표 정렬하기  (0) 2021.03.25
[C++] 백준 11170번 0의 개수  (0) 2021.03.25
[C++] 백준 1531번 투명  (0) 2021.03.23
[C++] 백준 1292번 쉽게 푸는 문제  (0) 2021.03.23
[C++] 백준 11050번 이항 계수1  (0) 2021.03.21
Comments