C++)
#include <string>
#include <cctype>
using namespace std;
int solution(string s) {
if (isdigit(s[0]))
return stoi(s);
else if (s[0] == '+')
return stoi(s.substr(1));
else
return stoi(s.substr(1)) * -1;
}
Python)
def solution(s):
if s[0] == '-':
return -1 * int(s[1:])
elif s[0] == '+':
return int(s[1:])
return int(s)'프로그래머스 > Level1' 카테고리의 다른 글
| [Level1] 푸드 파이트 대회 (C++/Python) (0) | 2023.02.07 |
|---|---|
| [Level 1] 시저 암호 (C++/Python) (0) | 2021.01.08 |
| [Level 1] 수박수박수박수박수박수? (C++/Python) (0) | 2021.01.08 |
| [Level 1] 서울에서 김서방 찾기 (C++/Python) (0) | 2021.01.08 |
| [Level 1] 소수 찾기 (C++/Python) (0) | 2021.01.08 |