统计数字2出现的次数 - C++代码实现
#include
int count2(int n) { int count = 0; while (n > 0) { if (n % 10 == 2) { count++; } n /= 10; } return count; }
int main() { int L, R; cin >> L >> R;
int count = 0;
for (int i = L; i <= R; i++) {
count += count2(i);
}
cout << count << endl;
return 0;
}
原文地址: https://www.cveoy.top/t/topic/qiKP 著作权归作者所有。请勿转载和采集!