백준 알고리즘 10824번 : 네 수

Zoo Da·2021년 7월 8일
0

백준 알고리즘

목록 보기
100/337
post-thumbnail

링크

https://www.acmicpc.net/problem/10824

문제

네 자연수 A, B, C, D가 주어진다. 이때, A와 B를 붙인 수와 C와 D를 붙인 수의 합을 구하는 프로그램을 작성하시오.

두 수 A와 B를 합치는 것은 A의 뒤에 B를 붙이는 것을 의미한다. 즉, 20과 30을 붙이면 2030이 된다.

입력

첫째 줄에 네 자연수 A, B, C, D가 주어진다. (1 ≤ A, B, C, D ≤ 1,000,000)

출력

A와 B를 붙인 수와 C와 D를 붙인 수의 합을 출력한다.

예제 입력 및 출력

풀이 코드(C++)

#include <iostream>
#include <algorithm>
#include <string> // stoll 함수 사용을 위함
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
using namespace std;

int main()
{
    fastio;
    string a, b, c, d, tempA, tempB;
    cin >> a >> b >> c >> d;
    tempA = a + b;
    tempB = c + d;
    ll result = stoll(tempA) + stoll(tempB); // stoll : string -> long long형변환
    cout << result;
    return 0;
}
profile
메모장 겸 블로그

0개의 댓글