#include <stdio.h> int two(int l, int r) { int cnt = 0; for (int i = l; i <= r; i++) { int temp = i;//暂时存储i的值 while (temp) { if (temp % 10 == 2) { cnt++; } temp /= 10; } } return cnt; } int main() { int l = 0; int r = 0; while (~scanf("%d %d", &l, &r)) { //统计数字2出现的次数 int cnt = two(l, r); //输出 printf("%d\n", cnt); } return 0; }