๋ฌธ์
์ฝ๋ฉํ ์คํธ ์ฐ์ต - ๋ฌธ์์ด ๋ด ๋ง์๋๋ก ์ ๋ ฌํ๊ธฐ
๋ฌธ์์ด๋ก ๊ตฌ์ฑ๋ ๋ฆฌ์คํธ strings์, ์ ์ n์ด ์ฃผ์ด์ก์ ๋, ๊ฐ ๋ฌธ์์ด์ ์ธ๋ฑ์ค n๋ฒ์งธ ๊ธ์๋ฅผ ๊ธฐ์ค์ผ๋ก ์ค๋ฆ์ฐจ์ ์ ๋ ฌํ๋ ค ํฉ๋๋ค. ์๋ฅผ ๋ค์ด strings๊ฐ ["sun", "bed", "car"]์ด๊ณ n์ด 1์ด๋ฉด ๊ฐ ๋จ์ด์ ์ธ๋ฑ
programmers.co.kr
์ฝ๋
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int index;
bool cmp(string a,string b){
if(a[index]!=b[index]) return a[index]<b[index];
else return a<b;
}
vector<string> solution(vector<string> strings, int n) {
vector<string> answer;
index=n;
sort(strings.begin(),strings.end(),cmp);
answer=strings;
return answer;
}
๋๊ธ