250x250
Notice
Recent Posts
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
관리 메뉴

일상 코딩

[C++/CPP] C++ 코딩테스트용 split() 본문

코딩테스트/inflearn C++ 코딩테스트

[C++/CPP] C++ 코딩테스트용 split()

polarcompass 2023. 12. 28. 22:23
728x90
Visual Studio에 <bits/stdc++.h> 헤더파일 추가하기

출처:https://hkhan.tistory.com/36

 

[C++] Visual Studio에 <bits/stdc++.h> 헤더파일 추가하기

알고리즘 문제를 풀 때, 필요한 헤더 파일들을 매번 include 해주는 과정이 귀찮게 느껴질 수 있다. 자주 쓰이는 헤더 파일들을 담은 stdc++.h 파일을 다운로드 받은 후, 코드 컴파일러의 include 파일

hkhan.tistory.com

stdc++.h
0.00MB

C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include

위 경로에서 " 14.33 .31629 "는 Visual Studio 버전이며 각자 다른 숫자일 수 있으니 불안하다면 각 폴더에 있는 include에 bits 폴더 복사 후 붙여넣기 해준다.

위 경로에서 "bits" 폴더 생성 후 "stdc++.h" 파일 넣는다.

#include<bits/stdc++.h>
// include 신경쓰지 않고 코딩에만 집중

int main() {
	// logic
}

 

C++ 온라인 컴파일러 사이트
  1. https://replit.com/~
  2. https://www.onlinegdb.com/online_c++_compiler
  3. https://cpp.sh/
  4. https://www.tutorialspoint.com/compile_cpp_online.php
1. split() 교안 버전
// C++ compile 사이트용(코딩테스트 사이트 / 백준)
#include <bits/stdc++.h>

using namespace std;

vector<string> split(string str, string delim) {
	vector<string> ret;
	auto start = 0;
	auto end = str.find(delim);

	while (end != string::npos) {
		ret.push_back(str.substr(start, end - start));
		start = end + delim.size();
		end = str.find(delim,start);
	}

	ret.push_back(str.substr(start));

	return ret;
}

int main() {
    string str = "1, 2, 3, 4, 5";

    // str을 ,로 분리합니다.
    vector<string> tokens = split(str, ", ");

    // 분리된 토큰을 출력합니다.
    for (const auto& token : tokens) {
        cout << token << endl;
    }
}

 

 

728x90