피너클의 it공부방
백준 15873 공백 없는 A+B (c++) : 피너클 본문
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
반응형
'백준' 카테고리의 다른 글
백준 1325 효율적인 해킹 (c++) : 피너클 (0) | 2022.08.15 |
---|---|
백준 13188 뉴턴과 사과 (c++) : 피너클 (0) | 2022.08.15 |
백준 17388 와글와글 숭고한 (c++) : 피너클 (0) | 2022.08.14 |
백준 17143 낚시왕 (c++) : 피너클 (0) | 2022.08.13 |
백준 1647 도시 분할 계획 (c++) : 피너클 (0) | 2022.08.13 |
Comments