Submission

Status:

PPPPPPPPPP

Subtask/Task Score:

100/100

Score: 100

User: haha_Inwza007

Problemset: ผลรวมของเลขหลัก

Language: cpp

Time: 0.003 second

Submitted On: 2026-09-27 10:23:28

#include <bits/stdc++.h>
using namespace std;

int main() {
  string s;
  cin >> s;
 // string s = "93512" ; 
  //s.length() = 5
 // s[0] =  '9' (char)
  // s[1] = '3' (char)
  // s[2] = '5' (char)
  // s[3] = '1' (char)
  // s[4] = '2' (char)

  int sum = 0;
  for (int i = 0; i < s.length(); i++){
    sum += s[i] - '0';
  }
  // cast type char to int (char - '0')
  // '5'  = 53
  // '5' - '0' = 53 - 48 = 5

  cout << sum;
  return 0;
}