2 条题解

  • 0
    @ 2022-7-17 10:18:05

    C++ :

    #include<iostream>
    using namespace std;
    int main()
    {
    	int L,R,x,s,a;
    	cin>>L>>R;
    	x=0;
    	for(int i=L;i<=R;i++)
    	{
    		s=i;
    		while(s!=0)
    		{
    		a=s%10;
    		if(a==2) x=x+1;
    		s=s/10;
    		}
    	}
    	cout<<x<<endl;
    	return 0;
    }
    

    Python :

    # coding=utf-8
    a,b=map(int,input().split())
    c=0
    for i in range(a,b+1):
        while i>0:
            if i%10==2:
                c+=1
            i//=10
    print(c)
    

    信息

    ID
    762
    时间
    1000ms
    内存
    64MiB
    难度
    4
    标签
    递交数
    283
    已通过
    133
    上传者