Official

A - Large Digits Editorial by en_translator


If you are new to learning programming and do not know where to start, please try Problem A “Welcome to AtCoder” from “practicecontest” (https://atcoder.jp/contests/practice/). There you can find a sample code for each language.


In this problem, you are asked to input \(A\) and \(B\), and output the greater of sums of digits of \(A\) and \(B\).
It will be easier to calculate the sum of digits if you receive \(A\) and \(B\) as strings.

Sample Code (C++)

#include <iostream>
#include <string>
using namespace std;

int S(string n){
    return (n[0] - '0') + (n[1] - '0') + (n[2] - '0');
}
int main(){
    string A, B;
    cin >> A >> B;
    cout << max(S(A), S(B)) << endl;
}

Sample Code (Python)

A, B = input().split()
A = int(A[0]) + int(A[1]) + int(A[2])
B = int(B[0]) + int(B[1]) + int(B[2])
print(max(A, B))

posted:
last update: