题目地址


#include<cstdio>
#include<iostream>
using namespace std;
int getTwoNum(int val){
	int cnt=0;
	while(val){
		int nowVal=val%10;
		if(nowVal==2)cnt++;
		val/=10;
	}
	return cnt;
}
int main(){
	int l,r;
	scanf("%d%d",&l,&r);
	int cnt=0;
	for(int i=l;i<=r;i++){
		cnt+=getTwoNum(i);
	}
	printf("%d\n",cnt);
	return 0;
}