cout 소수점 고정
·
C++
coutcout.precision(6) = 6자리까지 표현하겠다는 뜻.-> 버리는 자리 수는 반올림! cout해제 : cout.unsetf(ios::fixed)설정 : cout.setf(ios::fixed)로 표현 이 가능하다.
string::find
·
C++
string 클래스의 멤버함수 헤더 : #include 반환값 :1. 찾는 문자의 첫번째 인덱스 값2. 찾는 문자가 없는경우 string::npos를 리턴 (no position이라는 뜻으로 쓰레기 값) #include #include using namespace std;int solution(string str1, string str2) { int answer = 0; if(str1.find(str2)!=string::npos) { return 1; } else { return 2; } return answer;}
STL : sort algorithm
·
C++
헤더 : #include  sort(start,end) -> [start,end) 범위 인자 오름차순(default)정렬quick sort 기반으로 구현되어 있어 시간 복잡도는 n log n 사용법1. sort(arr,arr+n);2. sort(v.begin(),v.end());3. sort(v.begin(),v.end(), compare); //사용자 정의 함수4. sort(v.begin(),v.end(), greater()); //내림차순5. sort(v.begin(),v.end(), less()); //오름차순
c++ string을 통 특정 문자 제거
·
C++
#include #include using namespace std;string solution(string my_string, string letter) { my_string.erase(remove(my_string.begin(),my_string.end(), letter[0]),my_string.end()); return my_string;}remove(my_string.begin(), my_string.end(), letter[0]): 이 함수는 my_string의 시작부터 끝까지 탐색하면서 letter[0]과 일치하는 모든 문자를 "제거"합니다. 그런데 여기에서 "제거"는 실제로 해당 요소들을 문자열에서 삭제하는 것이 아니라, 문자열의 뒷부분으로 이동시키는 것을 의미합니다. remove..
string stream
·
C++
#include // 필수 헤더// stream.str(string str)은 현재 stream의 값을 문자열 str로 변환int num;string str = "123 456";stringstream stream;stream.str(str);while(stream >> num) cout
간단한 Queue 학습 및 제작
·
C++
#include #include using namespace std;class _Q_Node{public: _Q_Node(int in_data=0) { next_node = nullptr; data = in_data; } class _Q_Node* next_node; int data;};class _Q_head {public: _Q_head() { front = nullptr; rear = nullptr; size = 0; } _Q_Node* front; _Q_Node* rear; int size;};void push(_Q_head* in_q, int in_data){ _Q_Node* newnode = new _Q_Node(in_data); if (in_q->size == 0) { in_q..