-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from AlgoLeadMe/9-dhlee777
9-dhlee777
- Loading branch information
Showing
1 changed file
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#include<iostream> | ||
#include<vector> | ||
#include<string> | ||
#include<algorithm> | ||
using namespace std; | ||
vector<int>v; //λ°°μ΄μ μμλ€μ μ μ₯ν λ²‘ν° | ||
string a,b,nm; //a-λͺ λ Ήμ΄λ€μ μ μ₯ν string, b-λ°°μ΄μ μ μ₯ν string | ||
int main(void) { | ||
ios_base::sync_with_stdio(false); | ||
cin.tie(NULL); | ||
int t,num,start_idx,end_idx; //t-ν μ€νΈμΌμ΄μ€κ°μ,num-μμμκ°μ,start_idx-μμ μΈλ±μ€,end_idx-λμΈλ±μ€ | ||
int r_cnt = 0; | ||
cin >> t; | ||
while (t--) { | ||
cin >> a>>num>>b; | ||
start_idx = 0; end_idx = num - 1; | ||
r_cnt = 0; | ||
for (int i = 0; i <b.size(); i++) { | ||
if (b[i] == '[' || b[i] == ']') | ||
continue; | ||
else if (b[i] == ',') | ||
{ | ||
v.push_back(stoi(nm)); | ||
nm.clear(); | ||
} | ||
else | ||
nm = nm + b[i]; | ||
|
||
} | ||
if(!nm.empty()) v.push_back(stoi(nm)); | ||
nm.clear(); | ||
|
||
for (int i = 0; i < a.size(); i++) { | ||
if (a[i] == 'R') | ||
r_cnt++; | ||
else { //dλ₯Όμ€νν κ²½μ° | ||
if (end_idx == -1) //벑ν°λ΄μ μμκ° μλκ²½μ° | ||
{ | ||
r_cnt == 0; | ||
end_idx--; | ||
break; | ||
} | ||
if (r_cnt % 2) { //rμ΄ νμλ²λμμκ²½μ° μμμΈλ±μ€μ λμΈλ±μ€λ₯Ό λ°κΏμ€λ€. | ||
int temp = start_idx; | ||
start_idx = end_idx; | ||
end_idx = temp; | ||
} | ||
if (start_idx > end_idx) | ||
start_idx--; | ||
else if (end_idx > start_idx) | ||
start_idx++; | ||
else end_idx = -1; //μμμΈλ±μ€μ λμΈλ±μ€κ° κ°μκ²½μ°μ μμλ νλμ‘΄μ¬νλ―λ‘ dλ₯Ό μ€νν κ²½μ° λ²‘ν°κ° λΉκ²λλ€. | ||
r_cnt = 0; | ||
} | ||
} | ||
if (r_cnt != 0 && end_idx > -1&&r_cnt%2==1) { //μ μΌλμ rμ΄ μ¬κ²½μ° λΉ λ²‘ν°κ° μλκ³ rμκ°μκ° νμμΌλ | ||
int temp = start_idx; | ||
start_idx = end_idx; | ||
end_idx = temp; | ||
} | ||
|
||
if (end_idx == -2) cout << "error"<<"\n"; | ||
else if (end_idx == -1) cout << "[]"<<"\n"; | ||
else { | ||
cout << "["; | ||
if (start_idx >= end_idx) { | ||
for (int i =start_idx; i>end_idx; i--) { | ||
cout << v[i] << ","; | ||
} | ||
cout << v[end_idx]<<"]"<<"\n"; | ||
} | ||
else { | ||
for (int i = start_idx; i < end_idx; i++) { | ||
cout << v[i] << ","; | ||
} | ||
cout << v[end_idx]<<"]"<<"\n"; | ||
} | ||
|
||
} | ||
|
||
vector<int>().swap(v); //λ€λ₯Έ ν μ€νΈμΌμ΄μ€λ₯Ό μν λ²‘ν° μ΄κΈ°ν | ||
|
||
} | ||
|
||
|
||
} |