웅재의 코딩세상
[프로그래머스] 문자열을 정수로 바꾸기 본문
- 풀이
#include <string>
#include <vector>
using namespace std;
int solution(string s) {
int answer = 0;
answer = stoi(s);
return answer;
}
//부호 처리
//int sign = 1;
//if(s[0]=='-') {s.erase(0,1); sign = sign* (-1)}
//else if(s[0]=='+'){s.erase(0,1);}
//return sign*stoi(s);
반응형
'코딩테스트 > 프로그래머스 - LV 1' 카테고리의 다른 글
[프로그래머스] 서울에서 김서방 찾기 (0) | 2024.02.09 |
---|---|
[프로그래머스] 수박수박수박수박수박수? (0) | 2024.02.09 |
[프로그래머스] 약수의 합 (0) | 2024.02.09 |
[프로그래머스] 이상한 문자 만들기 (0) | 2024.02.09 |
[프로그래머스] 자릿수 더하기 (0) | 2024.02.09 |