4 条题解

  • 3
    @ 2023-1-4 10:01:01
    #include <bits/stdc++.h>
    using namespace std;
    int main()
    {
        int n, sum = 0;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
            int x = i;
            while (x > 0)
            {
                if (x % 10 == 8)
                {
                    sum++;
                }
                x /= 10;
            }
        }
        cout << sum;
        return 0;
    }
    
    • 1
      @ 2023-1-19 13:03:06

      AC代码1

      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
      	int n, m, s, a, k, x = 0;
      	cin >> n;
      	for (int i = 1; i <= n; i++)
      	{
      		k = i / 1000, a = i / 100 % 10, s = i / 10 % 10, m = i % 10;
      		if (k == 8)
      			x++;
      		if (a == 8)
      			x++;
      		if (s == 8)
      			x++;
      		if (m == 8)
      			x++;
      	}
      	cout << x;
      	return 0;
      }
      

      AC代码2

      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
      	cout << 3556;
      	return 0;
      }
      
      • 0
        @ 2024-4-15 19:56:47
        #include<iostream>
        using namespace std;
        int n,num;
        int main(){
            cin>>n;
            for(int i=8;i<=n;i++){
                int x=i;
                while(x!=0){
                    if(x%10==8)
                        num++;
                    x/=10;
                }
            }
            cout<<num;
            return 0;
        }//编者:Royal
        
        • 0
          @ 2023-7-20 19:19:29
          #include <cstdio>
          using namespace std;
          int eight(int x){
              int num=0;
              while(x>0){
                  if(x%10==8)num++;
                  x/=10;
              }
              return num;
          }
          int main(){
              int n,cnt=0;
              scanf("%d",&n);
              for(int i=1;i<=n;i++)cnt+=eight(i);
              printf("%d\n",cnt);
              return 0;
          }
          
          • 1

          信息

          ID
          984
          时间
          1000ms
          内存
          64MiB
          难度
          4
          标签
          递交数
          99
          已通过
          49
          上传者