[풀이 - Circular Array Rotation]
더보기
vector<int> circularArrayRotation(vector<int> a, int k, vector<int> queries)
{
vector<int> result;
//
vector<int> indices;
int count = a.size();
//
for(int i = 0; i < count; ++i)
{
int temp = (i - (k % count));
temp = (temp >= 0) ? temp : count + temp;
indices.push_back(temp);
}
//
for(int i = 0; i < queries.size(); ++i)
result.push_back(a[indices[queries[i]]]);
//
return result;
}
[풀이 - Sequence Equation]
더보기
vector<int> permutationEquation(vector<int> p)
{
vector<int> result;
//
int count = p.size();
vector<int> v(count, 0);
//
for(int i = 0 ; i < count ; ++i)
v[p[i]-1] = i;
//
for(int i = 0 ; i < count ; ++i)
result.push_back( v[v[i]] + 1 );
//
return result;
}