작성일 :

문제 링크

31615번 - 桁 (Digit)

설명

두 정수의 합을 십진수로 표현했을 때 자릿수를 구하는 문제입니다.


접근법

두 수의 합을 구한 뒤 문자열로 변환하여 길이를 출력합니다.


Code

C#

1
2
3
4
5
6
7
8
9
10
11
using System;

class Program {
  static void Main() {
    var a = int.Parse(Console.ReadLine()!);
    var b = int.Parse(Console.ReadLine()!);
    var s = a + b;

    Console.WriteLine(s.ToString().Length);
  }
}

C++

1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int a, b; cin >> a >> b;
  int s = a + b;

  cout << to_string(s).size() << "\n";

  return 0;
}