#include <iostream>
#include <string>
using namespace std;
//解题思路1
//拆分数字
//思路2
//利用to_string函数把每个数字转成字符串
//然后查找子串"2"
int main() {
int L,R,cnt=0;
cin>>L>>R;
for(int i=L;i<=R;i++)
{
string temp=to_string(i);
size_t newpos=0,oldpos=0;
while(newpos!=string::npos)//查找子串"2"
{
newpos=temp.find("2",oldpos);//从头开始查找
if(newpos!=string::npos)cnt++;//找到cnt++
oldpos=newpos+1;//更新下次查找的位置
}
}
std::cout<<cnt<<std::endl;
}
// 64 位输出请用 printf("%lld")
两种思路
//解题思路1
//拆分数字
//思路2
//利用to_string函数把每个数字转成字符串
//然后查找子串"2"

京公网安备 11010502036488号