题解 | #[NOIP2010]数字统计#
[NOIP2010]数字统计
https://www.nowcoder.com/practice/179d9754eeaf48a1b9a49dc1d438525a
#include <stdio.h> //函数名的意思是2出现的次数 int Number2OfOccurrences(int L, int R) { int count = 0; //记录二出现的次数 for(int i = L; i <=R; i++) { int tmp = i; while (tmp) { //判断余数为2,计数加一 if(tmp % 10 == 2) count++; tmp /= 10; } } return count; } int main() { int L, R; scanf("%d %d", &L, &R); int sum = Number2OfOccurrences(L, R); printf("%d", sum); }