3 条题解

  • 1
    @ 2023-11-20 20:49:33

    代码如下:

    #include <iostream>
    using namespace std;
    int main()
    {
        int n,c=0,n1,n2,n3,n4,n5,n6,n7,n8;//定义
        cin >> n;//输入
        for (int i=1;i<=n;i++)//循环
        {
            n1=i/10000000;//计算千万位
            n2=i%10000000/1000000;//计算百万位
            n3=i%1000000/100000;//计算十万位
            n4=i%100000/10000;//计算万位
            n5=i%10000/1000;//计算千位
            n6=i%1000/100;//计算百位
            n7=i%100/10;//计算十位
            n8=i%10;//计算个位
            if (n1+n2+n3+n4+n5+n6+n7+n8==13)//判断所有数位加起来是不是等于十三
            {
                c++;//计算个数
            }
        }
        cout << c;//输出
        return 0;//好习惯!
    }
    

    已AC,测试过

    • 0
      @ 2023-11-26 10:52:33

      没什么可讲的吧

      #include <bits/stdc++.h>
      using namespace std;
      bool ac(long long n)
      {
          int num = 0;
          while (n)
          {
              num += n % 10;
              n /= 10;
          }
          return num == 13;
      }
      int main()
      {
          ios::sync_with_stdio(false);
          cin.tie(0);
          cout.tie(0);
          long long n, ans = 0;
          cin >> n;
          for (register int i = 1; i <= n; i++)
          {
              if (ac(i))
                  ans++;
          }
          cout << ans << endl;
          return 0;
      }
      
      • 0
        @ 2023-1-16 10:00:42
        #include<bits/stdc++.h>
        using namespace std;
        int main()
        {
        	int n, s = 0, c = 0;
        	cin >> n;
        	for (int i = 1; i <= n; i++){
        		s = 0;
        		int t = i;
        		while(t != 0){
        			s = s + t % 10;
        			t /= 10;
        		}
        		if (s == 13){
        			c++;
        		}
        	}
        	cout << c << endl;
        	return 0;
        }
        
        
        
        • 1

        【入门】数字之和为13的整数

        信息

        ID
        508
        时间
        1000ms
        内存
        128MiB
        难度
        1
        标签
        递交数
        63
        已通过
        46
        上传者