알고리즘/프로그래머스
프로그래머스(C++, JAVA) / level 1 : 문자열을 정수로 바꾸기
clean_h
2022. 3. 25. 17:02
728x90
level 1 : 문자열을 정수로 바꾸기
🎯 코드(C++)
#include <string>
#include <vector>
using namespace std;
int solution(string s) {
int answer = 0;
answer = stoi(s);
return answer;
}
🎯 코드(JAVA)
class Solution {
public int solution(String s) {
int answer = 0;
answer = Integer.parseInt(s);
return answer;
}
}
🎯 설명
문자열을 정수로 바꾸기
- string s = "123"
- C++ : stoi(s);
- JAVA : Integer.parseInt(s);
정수를 문자열로 바꾸기
- int num = 1;
- C++ : to_string(num);
- JAVA : Integer.toString(num);
728x90