c++(2)
-
[C++]2차원 배열 내장 STL 함수로 SORT하기
2차원 벡터를 만든뒤 algorithm 헤더에 있는 sort함수를 사용한다. 이때 당연하게 cmp 함수를 커스텀해야 한다. 소스코드 #include #include #include using namespace std; vector v; bool cmp(vector a, vector b) { return a[2]>b[2]; } int main() { sort(v.begin(),v.end(),&cmp); }
2020.05.20 -
[c/c++]연속적인 숫자 또는 문자 입력을 한자리씩 끊어서 받아보자
백준이나 알고리즘 문제들을 풀다 보면 이런 식으로 연속적으로 숫자를 입력받아야 할 때가 있다. 이런 경우 cin으로 입력받게 되면 숫자 한개를 0100, 1110.. 이런 식으로 입력받게 되므로 사용이 어렵다. 생각보다 풀이가 매우 간단한데, scanf 함수에 옵션을 줄 수 있다. 따라서 이런 경우에는 scanf("%1d",&a) 이런 식으로 입력을 받아주면 한 자리씩 끊어서 입력을 받을 수 있다.
2019.09.25