6 条题解

  • 6
    @ 2023-1-3 9:52:10
    #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;
            if (x % 5 == 0)
            {
                while (x > 0)
                {
                    if (x % 10 == 5)
                    {
                        sum++;
                        break;
                    }
                    x /= 10;
                }
            }
        }
        cout << sum;
        return 0;
    }
    
    • @ 2023-9-26 15:20:35

      优化版的

      #include <iostream>
      using namespace std;
      int ans;
      bool check(int n)
      {
          while (n)
          {
              if (n % 10 == 5)
                  return true;
              n /= 10;
          }
          return false;
      }
      int main()
      {
          int n;
          cin >> n;
          for (int i = 1; i <= n; i++)
              if (check(i) && i % 5 == 0)
                  ans++;
          cout << ans;
          return 0;
      }
      
  • 2
    @ 2023-10-3 15:48:54

    代码如下(带题解):

    #include <iostream>
    using namespace std;
    int main()//头文件
    {
        int n,c=0;//定义
        bool a;//用来存储布尔值,详看L4-5
        cin >> n;//输入
        for (int i=1;i<=n;i++)
        {
            a=i/10000==5 or i%10000/1000==5 or i%1000/100==5 or i%100/10==5 or i%10==5;//满足一个条件a的值就是True了
            if (i%5==0 && a)//Ture=真的
            {
                c++;//数量增加1
            }
        }
        cout << c;//输出最终的数量
        return 0;//好习惯!(结束)
    }
    

    给个赞吧!

    • 2
      @ 2022-9-13 14:07:55
      #include <iostream>
      using namespace std;
      bool huan1(int n)
      {
          bool x=false;
          if (n%5==0)
          {
              x=true;
          }
          return x;
      }
      bool huan2(int n)
      {
          bool x=false;
          while (n>0)
      	{
      	    if (n%10==5)
      	    {
      	        x=true;
      	    }
      	    n/=10;
      	}
          return x;
      }
      int main()
      {
          int n, a=0;
          cin>>n;
          for (int i=5;i<=n;i++) if (huan1(i)&&huan2(i)) a++;
          cout<<a;
      	return 0;
      }
      
      • 1
        @ 2024-1-26 18:42:53

        这一道题说实话挺简单的,不就是数位拆分吗,我一个刚学到Level4的都会做~

        已AC,请放心食用

        #include <iostream>
        using namespace std;
        int main()
        {
            int n, x, o, sum = 0;
            cin >> n;
            for (int i = 1; i <= n; i++)
            {
                o = 0;
                x = i;
                while (x > 0)
                {
                    if (x % 10 == 5)
                    {
                        o = 1;
                    }
                    x /= 10;
                }
                if (i % 5 == 0 && o == 1)
                {
                    sum += 1;
                }
            }
            cout << sum;
            return 0;
        }
        
        • 养成好习惯,看后点个赞( •̀ ω •́ )✧!

        • 1
          @ 2023-10-3 19:43:59
          #include<bits/stdc++.h>
          using namespace std; 
          int n,sum;
          int main()
          {
              cin>>n;
              for(int i=1;i<=n;i++)
              {
                  if(i%5==0)
                  {
                      int m=i;
                      while(m>0)
                      {
                          if(m%10==5)
                          {
                              sum++;
                              m=0;
                              break;
                          }
                          m/=10;
                      }
                      
                  }
              }
              cout<<sum;
              return 0;
          }
          
          • 1
            @ 2022-9-3 10:56:25
            for (int i=5;i<=n;i+=5)
            {
                if (i%10==5 || i/10%10==5 || i/100%10==5 || i/1000%10==5)
                {
                    ans++;
                }
            }
            
            • 1

            【入门】能被5整除且至少有一位数字是5的所有整数的个数

            信息

            ID
            58
            时间
            1000ms
            内存
            16MiB
            难度
            3
            标签
            递交数
            224
            已通过
            126
            上传者