1 条题解

  • 2
    @ 2022-12-30 10:10:50

    简单得很(代码以AC)

    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int l, r, num = 0, x;
    	cin >> l >> r;
    	for(int i = l; i <= r; i++)
    	{
    		x = i;
        	while(x > 0)
        	{
            	if(x % 10 == 2)
    		    {
                    num++;
    		    }
            	x /= 10;
        	}
    	}
    	cout << num;
    	return 0;
    }
    

    各位,点个赞再走呗!

    • @ 2023-12-21 18:14:43

      又做了一次

      #include <bits/stdc++.h>
      using namespace std;
      int check(int n)
      {
          int sum = 0;
          while (n)
          {
              if (n % 10 == 2)
                  sum++;
              n /= 10;
          }
          return sum;
      }
      int main()
      {
          ios::sync_with_stdio(false);
          cin.tie(0);
          cout.tie(0);
          int l, r, ans = 0;
          cin >> l >> r;
          for (int i = l; i <= r; i++)
              ans += check(i);
          cout << ans << endl;
          return 0;
      }
      
  • 1

信息

ID
659
时间
1000ms
内存
128MiB
难度
1
标签
递交数
40
已通过
32
上传者