#include <bits/stdc++.h>
using namespace std;

int main()
{
	int l,r,sum=0;
	cin >> l >> r;
	while(r>=l)
	{
		int i=r ;
		while(i>0)
		{
			if(i%10==2)
			{
				sum++;
			}
			i/10;
		}
		r--;
	} 
	cout << sum << endl;
	return 0;
}

1 comments

  • @ 2023-10-25 19:30:04
    #include <bits/stdc++.h>
    using namespace std;
    
    int main()
    {
    	int l,r,sum=0;
    	cin >> l >> r;
    	while(r>=l)
    	{
    		int i=r ;
    		while(i>0)
    		{
    			if(i%10==2)
    			{
    				sum++;
    			}
    			i/=10; // 这里错了
    		}
    		r--;
    	} 
    	cout << sum << endl;
    	return 0;
    }
    
    👍 1
    • 1

    Information

    ID
    586
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    4
    Tags
    # Submissions
    169
    Accepted
    73
    Uploaded By