题目描述:
解题思路:
- 数字转化为字符串 itoa
- 用字符串处理
代码实现:
#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;
#define N 128
int Count(int m, int n) {
char num[N] = {0};
itoa(m, num, 10);
int cnt = 0;
int i = 0;
while (num[i] != '\0') {
if (num[i] - '0' == n) {
cnt++;
}
i++;
}
return cnt;
}
int main() {
int n, m;
cin >> n >> m;
int ans = Count(n, m);
cout << ans << endl;
return 0;
}