参考代码:
#include<iostream> #include<string> #include<sstream> using namespace std; int main() { int n, num = 0; string s; cin >> n; for (int i = 1;i <= n;i++) { stringstream ss; ss << i; s = ss.str(); for (int j = 0;j <= s.size();j++) { if (s[j] == '1') num++; } } cout << num ; return 0; }
0.0分
0 人评分