본문 바로가기

프로그래밍 언어/c c++8

[c c++] isdigit 함수 문자가 숫자인지 확인해주는 함수 헤더 c에선: #include c++에선: #include 함수 원형 int isdigit(char c); c가 10진수 숫자로 변경가능하면 0이 아닌 수를 리턴, 아니면 0을 리턴 2020. 10. 19.
[c++] STL priority_queue 우선순위 큐 c++ STL 중 하나인 우선순위 큐에 대해 알아보자. 큐와 동일하지만 안에서 정렬이 된다는 점이 다르다. - 헤더는 #include - 선언은 priority_queue pq - 자료형은 int, double, class - 구현체는 기본적으로 vector - 비교연산자의 기본값은 less 내림차순, greater 오름차순 정렬 가능 - push/pop을 하는 경우 시간 복잡도는 logN - 자료형이 pair라면 우선적으로 a를 확인하고 a가 같으면 b에 따라 결정된다. -pq.push(input) -pq.pop() -pq.top() : front 없음. iterator없음 -pq.empty() -pq.size() #include #include #include #define pi pair int ma.. 2020. 10. 19.
[c++] 문자열을 특정 문자 기준으로 자르기2 getline & stringstream 정석은 아니지만... getline을 사용하면 문자열을 손쉽게 자를 수 있다. getline(&istream is, &string str, char delim) - is는 cin이나 stringstream - str은 자른 문자열 - delim은 기준점이다. 원래 정의대로 라면 delim 문자를 만나면 문자열 추출이 중단된다. 이걸 이용해서 tokenize해보자. 일단 is 자리에 들어갈 stringstream이 필요하다. #include #include #include using namespace std; int main(void){ string s = "This,is,the,test!"; char delim = ' '; stringstream ss(input); string buffer; while(.. 2020. 10. 10.
[c++] accumulate 함수 - 배열 안에 모든 값을 더하는 함수 #include using namespace std int main(void){ vector v; //v 벡터 전체 합: 시작점, 마지막, 처음 시작 값 int sum = accumulate(v.begin(), v.end(), 0); //long long을 쓰려면 long long sum = accumulate(v.begin(), v.end(), 0LL); } 2020. 10. 6.