Skip to content

Commit

Permalink
Merge pull request #42 from AlgoLeadMe/9-dhlee777
Browse files Browse the repository at this point in the history
9-dhlee777
  • Loading branch information
dhlee777 authored May 19, 2024
2 parents de75008 + f49b420 commit f55e54f
Showing 1 changed file with 86 additions and 0 deletions.
86 changes: 86 additions & 0 deletions dhlee777/λ¬Έμžμ—΄μ²˜λ¦¬/AC.cpp
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); //λ‹€λ₯Έ ν…ŒμŠ€νŠΈμΌ€μ΄μŠ€λ₯Ό μœ„ν•œ 벑터 μ΄ˆκΈ°ν™”

}


}

0 comments on commit f55e54f

Please sign in to comment.