컨테이너 내의 순서 == 많이 쓰이는 순서
public static void Main(string[] args)
{
int array[3][2] =
{
{1, 2},
{3, 4},
{5} // 3번째 행은 5, 0으로 초기화
};
int array[3][5] = { 0 }; // 모두 0으로 초기화
}
multiset: vector가 정렬이 필요할 때 사용
deque: vector를 앞뒤에서 push, pop해야할 때 사용
#include <vector>
#include <set>
using namespace std;
void solution(vector<int> array, vector<vector<int>> commands) {
for(int i = 0; i < commands.size(); i++)
{
int begin = commands[i][0] - 1;
int end = commands[i][1];
// vector -> set (선언할 때 범위 지정)
multiset<int> sorting(array.begin() + begin, array.begin() + end);
// set -> vector (assign 내장함수 사용)
vector<int> sortedarray;
sortedarray.assign(sorting.begin(), sorting.end());
}
}
#include <string>
public void contains()
{
// c++에는 contains()가 아직도 없다..ㅎ 그래서 find()를 쓴다
string a = "abc";
string b = "ab";
if (a.find(b) != string::npos)
{
// a가 b를 포함함! (npos = no position)
}
else
{
// a가 b를 포함하지 않음
}
}
public void substring()
{
string a = "abcdefg";
a.substr(0, 3); // 인덱스 0부터 문자 3개 추출 -> "abc"
}
public void compare()
{
string a = "abc";
string b = "def";
a.compare(b); // 둘이 같으면 0, 다르면 0이아닌숫자 리턴
}
public void print()
{
// cout으로는 바로 출력할 수 있지만, printf로 출력할땐 변환작업이 필요함
string a = "aa";
printf("%s", a.c_str());
}
iterator를 지원하지 않아 용도가 한정적임.
힙 구현시 사용!