1. 가운데 글자 가져오기
#include <string>
#include <vector>
using namespace std;
string solution(string s) {
string answer = "";
if(s.size()%2==1){ //홀
answer=s[s.size()/2];
}else{//짝
answer=s[s.size()/2 - 1];
answer+=s[s.size()/2];
}
return answer;
}
2. 2016년 🐸
#include <string>
#include <vector>
using namespace std;
string solution(int a, int b) {
string ans = "";
string day[7]={"FRI","SAT","SUN","MON","TUE","WED","THU"}; // 1/1->FRI
int mth[13]={0,31,29,31,30,31,30,31,31,30,31,30,31};
int sum=0;
for(int i=0;i<a;i++){
sum+=mth[i]; // 해당 mth까지 더함
}
sum+=b-1; // 1일부터 b일까지 일수
ans=day[sum%7]; // 일주일 반복하기 때문
return ans;
}
3. 문자열 내 마음대로 정렬하기 🐸
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int k;
bool diction (string a, string b) {
if (a[k] != b[k])
return a[k] < b[k];
else
return a < b;
}
vector<string> solution(vector<string> strings, int n) {
vector<string> answer=strings;
k=n;
sort(answer.begin(), answer.end(), diction);
return answer;
}