4 条题解

  • 0
    @ 2025-10-23 23:10:34
    #include <bits/stdc++.h>
    using namespace std;
    int number(int n)
    {
        int t=0;
        int s = 0;
        while(n!=0)
        {
            t = n;
            t = t%10;
            s+=t;
            n/=10;
        }
        if(s<10)
        {
            return s;
        }
        else
        {
            return number(s);
        }
    }
    int main()
    {
        int n;
        cin>>n;
        cout<<number(n);
    }
    
    • 0
      @ 2025-10-23 23:10:09

      地龟,啊呸,递归是个好东西

      文本 #include <bits/stdc++.h> using namespace std; int number(int n) { int t=0; int s = 0; while(n!=0) { t = n; t = t%10; s+=t; n/=10; } if(s<10) { return s; } else { return number(s); } } int main() { int n; cin>>n; cout<<number(n); }

      • 0
        @ 2025-6-2 17:22:22

        #include <bits/stdc++.h> using namespace std; int main(){ int a,b=0; cin>>a; while(a>9){ b=0; for(int i=a;i>0;i/=10){ b=b+i%10; } a=b; } cout<<b; return 0; }

        • 0
          @ 2024-10-4 11:42:01
          #include<bits/stdc++.h>
          using namespace std;
          int main() {
          	int a,b=0;
          	cin>>a;
          	while(a>9){
          		b=0;
          		for(int i=a;i>0;i/=10){
          			b=b+i%10;
          		}
          		a=b;
          	}
          	cout<<b;
          	return 0;
          }
          
          • 1

          信息

          ID
          110
          时间
          1000ms
          内存
          256MiB
          难度
          6
          标签
          递交数
          26
          已通过
          11
          上传者