18 条题解

  • 8
    @ 2022-10-16 11:22:54
    #include <iostream>
    using namespace std;
    int main()
    {
        int n;
        cin >> n;
        cout << n % 10 + n % 100 / 10 + n % 1000 / 100 + n / 1000;
    }
    
    • 7
      @ 2022-12-25 13:17:34
      #include <bits/stdc++.h>
      using namespace std;
      int main()
      {
          int n, sum = 0;
          cin >> n;
          while (n > 0)
          {
              sum += n % 10;
              n /= 10;
          }
          cout << sum;
          return 0;
      }
      
      • 5
        @ 2023-4-26 19:51:57
        #include<bits/stdc++.h>
        using namespace std;
        
        int main()
        {
        	int n,a,b,c,d;
        	cin>>n;
        	a=n%10;   //个位 
        	b=n/10%10;   //十位 
        	c=n/100%10;   //百位 
        	d=n/1000;   //千位 
        	cout<<a+b+c+d;   //和 
        	
        	return 0;
        }
        
        • 3
          @ 2023-9-3 16:35:48

          其实不用那么麻烦的……:

          #include <bits/stdc++.h>
          using namespace std;
          int main()
          {
              string a;
              cin >> a;
              cout << (a[0] - '0') + (a[1] - '0') + (a[2] - '0') + (a[3] - '0');
              return 0;
          }
          
          • 3
            @ 2023-8-16 20:06:52

            又是贱贱担担的一道题辣👀️ 上代码🚀️

            #include <bits/stdc++.h>
            using namespace std;
            int s;
            int main()
            {
            string n;
            cin >> n;
            for (int i = 0; i < 4 ; i++) s += n[i] - '0';//直接遍历字符串再累加
            cout << s;
            return 0;
            }
            

            已AC,观众老爷勿喷👀️

            • 2
              @ 2023-3-6 13:04:16

              `

              #include<bits/stdc++.h>
              using namespace std;
              int main()
              {
                  int n;
                  cin >> n;
                  int a = n / 1000;
                  int b = n / 100 % 10;
                  int c = n / 10 % 10;
                  int d = n % 10;
                  cout << a + b + c + d;
                  return 0;
              }
              
              • 1
                @ 2023-8-23 11:58:13

                过辣!

                    string s;
                    long long sum=0;
                    cin>>s;
                    for (int i=0;i<s.length();++i)
                    {
                        sum+=(s[i]-'0');
                    }
                    cout<<sum;
                
                • 1
                  @ 2023-2-24 18:48:57
                  #include<bits/stdc++.h>
                  using namespace std;
                  int main()
                  {
                      int n,sum=0;
                      cin>>n;
                      while(n)
                      {
                           sum+=n%10;
                           n/=10;
                      }
                      cout<<sum;
                  }//简单  已AC
                  
                  • @ 2023-8-23 12:00:08

                    你这只能在DevC++上运行,return都没有

                • 1
                  @ 2022-9-1 17:26:34
                  while(n)
                  {
                      ans+=n%10;
                      n/=10;
                  }
                  
                  • 0
                    @ 2023-12-11 18:23:12
                    #include <bits/stdc++.h> 
                    using namespace std;
                    #define ll long long
                    #define s string
                    ll sum;
                    s n;
                    int main(){
                        cin>>n;
                        cout<<(n[0]-'0')+(n[1]-'0')+(n[2]-'0')+(n[3]-'0');
                        return 0;
                    }
                    
                    • 0
                      @ 2023-10-28 21:02:30
                      #include <iostream>
                      using namespace std;
                      int main(){
                          int x,sum=0;
                          cin>>x;
                          while(x)sum+=x%10,x/=10;
                          cout<<sum<<endl;
                          return 0;
                      }
                      
                      • 0
                        @ 2023-8-31 14:28:08

                        //已AC,勿喷❤️ ;

                        #include <bits/stdc++.h>
                        using namespace std;
                        int main(){
                            int n,g,s,b,q;
                            cin >> n;
                            q = n / 1000;
                            b = n / 100 % 10;
                            s = n / 10 % 10;
                            g = n % 10;
                            cout << q + b + s + g;
                            return 0;
                        } 
                        
                        • -1
                          @ 2024-1-18 14:21:16
                          #include <iostream>
                          using namespace std;
                          int main()
                          {
                              int n;
                              cin >> n;
                              cout << n % 10 + n % 100 / 10 + n % 1000 / 100 + n / 1000;
                          }
                          
                          • -1
                            @ 2024-1-13 21:17:22

                            Python解题:

                            a = input()
                            ans = 0
                            for i in a:
                                ans += int(i)
                            print(ans)
                            
                            • -2
                              @ 2022-12-17 20:10:37

                              少了return 0;

                            • -2
                              @ 2022-7-26 21:25:41

                              #include <iostream> using namespace std; int n,sum; int main() { cin>>n; while(n>0) { sum+=n%10; n/=10; } cout<<sum; return 0; }

                              • -2
                                @ 2021-12-9 17:02:31

                                #include<bits/stdc++.h> using namespace std; int main(){ int n,s=0,a,b,c,d; cin>>n; a=n/1000; b=n/100-a10; c=n/10-a100-b10; d=n-a1000-b100-c10; s=a+b+c+d; cout<<s; return 0; }

                                • -3
                                  @ 2022-12-25 13:16:52
                                  #include <bits/stdc++.h>
                                  using namespace std;
                                  int main()
                                  {
                                      cout << 3;
                                      return 0;
                                  }
                                  

                                  这么写得33分

                                • 1

                                信息

                                ID
                                387
                                时间
                                1000ms
                                内存
                                16MiB
                                难度
                                3
                                标签
                                递交数
                                515
                                已通过
                                289
                                上传者