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
'알고리즘 > 프로그래머스' 카테고리의 다른 글
프로그래머스(C++, JAVA) / level 1 : 약수의 합 (0) | 2022.03.30 |
---|---|
프로그래머스(C++, JAVA) / level 1 : 서울에서 김서방 찾기 (0) | 2022.03.30 |
프로그래머스(C++, JAVA) / level 1 : 수박수박수박수박수박수? (0) | 2022.03.25 |
프로그래머스(C++, JAVA) / level 1 : 내적 (0) | 2022.03.25 |
프로그래머스(C++, JAVA) / level 1 : 음양 더하기 (0) | 2022.03.25 |
댓글