백준 20499 Darius님 한타 안 함?
2023. 4. 8. 11:25ㆍ코딩 공부 연습
반응형
오랜만에 코테 문제다! 요즘 쉬운거 위주로 풀고 있어서 올릴일이 없었는데, c++ 에선 split을 사용할 수 없다는 불편함을
이번 기회에 해결해 보고자 split 함수를 구현해 보았다.
vector<string> split(string input, char delimiter) {
vector<string> answer;
stringstream ss(input);
string temp;
while (getline(ss, temp, delimiter)) {
answer.push_back(temp);
}
return answer;
}
이 split 을 외우고 다닌다면 쉽게 c++에서도 split 을 이용할 수 있다!!!
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
using namespace std;
vector<string> split(string input, char delimiter) {
vector<string> answer;
stringstream ss(input);
string temp;
while (getline(ss, temp, delimiter)) {
answer.push_back(temp);
}
return answer;
}
int main()
{
string input;
cin>>input;
vector<string> result = split(input, '/');
int k = stoi(result[0]);
int d = stoi(result[1]);
int a = stoi(result[2]);
if (k + a < d || d == 0)
{
cout<<"hasu\n";
return 0;
}
cout<<"gosu\n";
return 0;
}
stoi 함수를 통해 스트링을 바로 int로 바꿀 수 있단 것도 알았다..!!!!!
'코딩 공부 연습' 카테고리의 다른 글
DP 문제 풀이 유형 (1) | 2023.05.15 |
---|---|
백준 2075 N번째 큰 수 (1) | 2023.04.15 |
프로그래머스 - 숫자 게임 (2) | 2023.03.30 |
백준 11718 그대로 출력하기 (0) | 2023.03.22 |
백준 2741 N 찍기 (0) | 2023.03.12 |