12 条题解

  • 1
    @ 2023-12-11 18:08:12
    #include <bits/stdc++.h> 
    using namespace std;
    #define ll unsigned long long
    int main(){
        cout<<271;
        return 0;
    }
    
  • 1
    @ 2023-11-15 20:27:28

    #include<bits/stdc++.h> using namespace std; int main() { int a,c,sum=0; for(int i=1;i<=1000;i++){ a=i; while(a!=0){ c=a%10; if(c==3){ sum++; break; } a=a/10; } } cout<<sum; return 0; }

    • 1
      @ 2023-10-21 21:02:37

      代码如下图:

      #include <iostream>
      using namespace std;
      int mian()//头文件
      {
          int c=0;//把计数变量归零
          for (int i=1;i<1000;i++)
          {
              if (i%10==3)//判断如果i的个位是3
              {
                  c++;
              }
              else if (i%100/10==3)//判断如果i的十位是3
              {
                  c++;
              }
              else if (i/100==3)//判断如果i的百位是3
              {
                  c++;
              }
          }
          cout << c;//输出c
          return 0;
      }
      
      错误粗线!
      被你发现了!
      ……
      #include <iostream>
      using namespace std;
      int main()//头文件
      {
          int c=0;//把计数变量归零
          for (int i=1;i<1000;i++)
          {
              if (i%10==3)//判断如果i的个位是3
              {
                  c++;
              }
              else if (i%100/10==3)//判断如果i的十位是3
              {
                  c++;
              }
              else if (i/100==3)//判断如果i的百位是3
              {
                  c++;
              }
          }
          cout << c;//输出c
          return 0;
      }
      
      • 1
        @ 2023-10-3 14:54:52
        #include <bits/stdc++.h>
        using namespace std;
        int main()
        {
            int num = 0;
            for (int i = 1; i <= 1000; i++)
            {
                int x = i;
                while (x > 0)
                {
                    if (x % 10 == 3)
                    {
                        num++;
                        break;
                    }
                    x /= 10;
                }
            }
            cout << num;
            return 0;
        }
        
        
        • 1
          @ 2023-9-6 19:56:44
          #include<bits/stdc++.h>
          using namespace std;
          int main()
          {
              int b = 0;
              for (int i = 1; i <= 1000; i++)
              {
                  int x = i;
                  while (x > 0)
                  {
                      if (x % 10 == 3)
                      {
                          b++;
                          break;
                      }
                      x /= 10;
                  }
              }
              cout << b;
              return 0;
          }
          

          A

          • 1
            @ 2023-7-7 13:03:21
            #include <iostream>
            using namespace std;
            int main()
            {
            	int sum = 0;
            	for (int i = 1; i <= 1000; i++)
            	{
            		if (i / 100 == 3 || i % 100 / 10 == 3 || i % 100 % 10 == 3)//个位十位百位有一个有3就彳亍
            		{
            			sum++;
            		}
            	}
            	cout << sum;
            	return 0;
            }
            
            
            • 1
              @ 2023-3-8 12:45:12
              #include <bits/stdc++.h>
              using namespace std;
              int main()
              {
                  cout << 271;
                  return 0;
              }
              
              • 1
                @ 2022-12-24 17:19:38
                #include <bits/stdc++.h>
                using namespace std;
                int main()
                {
                    int num = 0;
                    for (int i = 1; i <= 1000; i++)
                    {
                        int x = i;
                        while (x > 0)
                        {
                            if (x % 10 == 3)
                            {
                                num++;
                                break;
                            }
                            x /= 10;
                        }
                    }
                    cout << num;
                    return 0;
                }
                
                • 1
                  @ 2022-11-18 21:30:31
                  #include <iostream>//hetao3097453
                  using namespace std;
                  int num = 0;
                  int main()
                  {
                      for(int i = 1;i <= 1000;i++)
                      {
                          if(((i % 10 == 3 || i % 100 / 10 == 3) || (i % 1000 / 100 == 3 || i / 1000 == 3)))
                          {
                              num++;
                          }
                      }
                      cout << num;
                      return 0;
                  }
                  
                  • 1
                    @ 2022-7-20 21:21:30
                    这题稍微推理下,我们可以发现个规律
                    	个位3时:十位,百位可以是0~9的任意数,即10x10种
                    	十位3时:个位,百位可以是0~9的任意数,但个位3算过了,个位不能再为3,即10x9种
                    	百位3时:个位,十位可以是0~9的任意数,但个,十位3算过了,个,十位不能再为3,即9x9种
                    相加即可
                    完美的避免了超时的困扰
                    上代码!
                    
                    #include <iostream>
                    using namespace std;
                    int main(){
                    	cout << (
                    		10*10+ //个位3
                    		10*9+ //十位3,个位三已经算过,排除 
                    		9*9 //同上
                    	);//也可以在草稿纸上算出来直接cout << 数;
                    	return 0 ;
                    }
                    
                    • 1
                      @ 2022-3-26 8:48:48
                      #include<bits/stdc++.h>
                      using namespace std;
                      int main()
                      {
                          int num=0;
                          for(int i=1;i<=1000;i++)
                          {
                              if(i%10==3||i/10%10==3||i/100%10==3||i/1000==3)
                              {
                                  num++;
                              }
                          }
                          cout<<num;
                          return 0;
                      }
                      
                      • 0
                        @ 2022-8-24 22:17:49

                        我们可以非常不讲武德的直接算出来: 方法1: 1 ~ 9有1个 10 ~ 99有9个 100 ~ 999有261个 1+9+261=271 方法2: 1010+109+9*9=271

                        • 1

                        【入门】所有不超过1000的数中含有数字3的自然数

                        信息

                        ID
                        57
                        时间
                        1000ms
                        内存
                        16MiB
                        难度
                        3
                        标签
                        递交数
                        324
                        已通过
                        170
                        上传者