BASIC
stoi(str);
#include <string>
to_string(int);
for(int a=0; a<arr.size(); a++){
a+=1
}
int arr[]={1,2,3,4,5};
for(int a : arr) {
a+=1;
}
for(int &a : arr) {
a+=1;
}
int solution(int a, int b, bool flag) {
return flag? a+b:a-b;
}
if (word.find(c)!=string::npos)
VECTOR
STRING
#include <string>
string numbers = "0123456789";
string full = numbers.substr();
string sub = numbers.substr(3, 5);
sstream
#include <sstream>
int num;
string word="1234 345:무야호";
stringstream stream;
stream.str(word);
while (stream>>num){
cout<<num<<endl;
}
stream.str("");
ALGORITHM
v.erase(v.begin() + i);
v.erase(remove(v.begin(), v.end(), 3), v.end())
QUEUE
https://school.programmers.co.kr/learn/courses/30/lessons/159994?language=cpp
#include <string>
#include <vector>
#include <queue>
string solution(vector<string> cards1, vector<string> cards2, vector<string> goal) {
string answer = "";
queue<string> q1;
queue<string> q2;
for (string card:cards1){
q1.push(card);
}
for (string card:cards2){
q2.push(card);
}
for (auto target : goal){
if(q1.size()>0 and target==q1.front()){
q1.pop();
}
else if(q2.size()>0 and target==q2.front()){
q2.pop();
}
else{
return "No";
}
}
return "Yes";
}
map, unordered_map
#include <map>
#include <unordered_map>
map<char, int> m1;
m1[key]=value;
for (auto di:dict){
cout<<di.first<<" "<<di.second<<endl;
}
sstream
vector<string> split(string input, char delimiter) {
vector<string> answer;
stringstream ss(input);
string temp;
while (getline(ss, temp, delimiter)) {
answer.push_back(temp);
}
return answer;
}
sort
#include <algorithm>
sort(v.begin(), v.end());
sort(v.begin(), v.end(), compare);
sort(v.begin(), v.end(), greater<자료형>());
sort(v.begin(), v.end(), less<자료형>());
존 나 어 렵 다
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <sstream>
using namespace std;
vector<string> split(string input, char delimiter) {
vector<string> answer;
stringstream ss(input);
string temp;
while (getline(ss, temp, delimiter)) {
answer.push_back(temp);
}
return answer;
}
vector<int> solution(vector<string> park, vector<string> routes) {
vector<int> answer;
pair<int,int> current;
for (int i=0;i<park.size();i++){
for (int j=0;j<park[0].size();j++){
if (park[i][j]=='S'){
current=make_pair(i, j);
}
}
}
map<string,pair<int,int>> directions;
directions["E"]=make_pair(0,1);
directions["W"]=make_pair(0,-1);
directions["S"]=make_pair(1,0);
directions["N"]=make_pair(-1,0);
for (auto route:routes){
vector<string> info=split(route, ' ');
string dir=info[0];
int dist=stoi(info[1]);
int x=current.first;
int y=current.second;
bool flag=true;
for (int i=0;i<dist;i++){
x+=directions[dir].first;
y+=directions[dir].second;
if (x<0 || y<0 || park.size()<=x || park[0].size()<=y || park[x][y]=='X'){
flag=false;
break;
}
}
if (flag){
current.first=x;
current.second=y;
}
}
answer.push_back(current.first);
answer.push_back(current.second);
return answer;
}