Notice
Recent Posts
Recent Comments
Link
250x250
«   2025/07   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
Archives
Today
Total
관리 메뉴

피너클의 it공부방

백준 15873 공백 없는 A+B (c++) : 피너클 본문

백준

백준 15873 공백 없는 A+B (c++) : 피너클

피너클 2022. 8. 14. 20:30
728x90
반응형

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

 

15873번: 공백 없는 A+B

자연수 A, B (0 < A, B ≤ 10)가 첫 번째 줄에 주어진다. 단, 두 수의 사이에는 공백이 주어지지 않는다. 두 수의 앞에 불필요한 0이 붙는 경우는 없다.

www.acmicpc.net

구현문제다.

길이가 2라면 A, B둘다 1의 자리수이고

길이가 3이라면 A, B둘중 하나는 10이다.

길이가 4라면 무조건 A, B둘다 10이다.

#include <iostream>
#include <string>

using namespace std;

int a = 0, b = 0;
string str;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> str;
	if (str.length() == 2) {
		cout << str[0] - '0' + str[1] - '0';
	}
	else if (str.length() == 3) {
		if (str[1] == '0') {
			cout << (str[0] - '0') * 10 + str[2] - '0' << endl;
		}
		else {
			cout << (str[1] - '0') * 10 + str[0] - '0' << endl;
		}
	}
	else {
		cout << (str[0] - '0') * 10 + (str[2] - '0') * 10 << endl;
	}
}

전체코드다.

728x90
반응형
Comments