题解 P1179 【数字统计】

· · 题解

include<bits/stdc++.h>

using namespace std; int num,n,m=0,mun; int main(){ cin>>num>>n;//输入不解释 for(int i=num;i<=n;i++){ mun=i;//为了不改变循环变量,新建一个变量把它存进去 while(mun!=0){ if(mun%10==2){ m++;//若取余为2,则加一次次数 } mun/=10; } } cout<<m;//输出 return 0; }