AC
2024-09-15 13:41:26
发布于:天津
0阅读
0回复
0点赞
#include <iostream>
#include <string>
using namespace std;
int countOnes(int n) {
int count = 0;
for (int i = 1; i <= n; i++) {
string numStr = to_string(i);
for (char c : numStr) {
if (c == '1') {
count++;
}
}
}
return count;
}
int main() {
int n;
cin >> n;
int onesCount = countOnes(n);
cout << onesCount << endl;
return 0;
}
这里空空如也
有帮助,赞一个