프로그래머스 - 문자열을 정수로 바꾸기(Lv1)

108번뇌·2020년 10월 4일
0

!

#include <string>
#include <vector>

using namespace std;

int solution(string s) {
    int answer = 0;
    
    if(s.at(0)=='+')
    {
       answer=stoi(s.substr(1));
    }
    else if(s.at(0)=='-')
    {
        answer=stoi(s);
    }
    else
    {
        answer = stoi(s);
    }
    return answer;
}

[익힐것]
string s;
s.at(0) : s의 맨앞 반환
stoi : string to int
substr : string을 index부터 len만큼 잘라서 반환하는 함수, 스트링 짤라서 반환.

https://blockdmask.tistory.com/338 : string 관련

profile
내일 아침 눈을 떳을 때, '기대되는 오늘 하루를 만들기 위해' 나는 오늘도 생각하고 고민한다.

0개의 댓글