-
Notifications
You must be signed in to change notification settings - Fork 1
12-froglike6 #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
12-froglike6 #46
Conversation
| err = False | ||
| for i in func: | ||
| if i == "R": | ||
| rev = not rev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ§€μ° μ¬μν 건λ°
rev ^= True0, 1μ ν립νλ κ±°λ€ λ³΄λ xor 1 ν΄μ£Όλ κ±Έλ‘λ κ°λ₯νκΈ΄ ν©λλ€ γ γ
dohyeondol1
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AC....μ§μ§ νλ©΄μ μ΄κ² λ§λ μΆλλ‘ κΉλνμ§ μμ μ½λκ° λμμ ACλ₯Ό λΆλ₯΄κ²λλ...
μ λ κ·Έλ₯ λ°°μ΄ μ 체λ₯Ό λ€μ§μ΄ νμ΄λ³΄λ €κ³ νλλ° λ°λ‘ νλ Έμ΅λλ€ γ
Dκ° "첫λ²μ§Έ μλ₯Ό λ²λ¦¬λ ν¨μ"λΌλ μ μ μ§μ€νλ κ·Έμ μΌ λ±μ μ¬μ©ν΄μΌκ² λ€λ μκ°μ΄ λ€λλΌκ΅¬μ..
C++
#include <iostream>
#include <vector>
#include <deque>
#include <string>
using namespace std;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int T;
cin >> T;
while(T--) {
string order;
int N;
cin >> order >> N;
deque<int> dq;
char ch;
cin >> ch;
for(int i = 0; i < N; i++) {
int x;
cin >> x;
dq.push_back(x);
if(i != N - 1) cin >> ch;
}
cin >> ch;
bool isReverse = false, isError = false;
for(char c : order) {
if(c == 'R') {
isReverse = !isReverse;
} else if(c == 'D') {
if(dq.empty()) {
isError = true;
break;
}
if(!isReverse) dq.pop_front();
else dq.pop_back();
}
}
if(isError) {
cout << "error" << '\n';
} else {
cout << '[';
if(!dq.empty()) {
if(!isReverse) {
for(size_t i = 0; i < dq.size(); i++) {
cout << dq[i];
if(i != dq.size() - 1) cout << ',';
}
} else {
for(size_t i = dq.size(); i-- > 0;) {
cout << dq[i];
if(i != 0) cout << ',';
}
}
}
cout << "]" << '\n';
}
}
return 0;
}μ
λ ₯μ [ μ , λ₯Ό μκ° λͺ»νλ€κ° ν리기λ νμ΅λλ€.. λ°©μ¬μ κΈλ¬Ό..
hadongun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
λ§€λ² Rμ΄ λμ¬ λλ§λ€ λ€μ§μΌλ μκ°μ΄ λ§€μ° κ±Έλ¦¬λκ΅°μ
λ€λ€ νμ λ°©λ²μ²λΌ bool νμ
μ reverse λ³μλ₯Ό ν΅ν΄ λ€μ§μ΄μ‘λμ§, μλμ§λ₯Ό νμΈν΄
pop, popleftλ₯Ό ν΅ν΄ ν΄κ²°νμ΅λλ€..!
μ μ λ¬Έμ λ€μ λμ΄λκ° λμμ§μλ‘ κ°κ²°νκ³ ν¨μ¨μ μΈ μ½λλ₯Ό μꡬνλ κ² κ°λ€μ
νμ΄μ¬
import sys
from collections import deque
t = int(input())
for _ in range(t):
is_reverse = False
implement = sys.stdin.readline().strip()
n = int(input())
arr = sys.stdin.readline().strip()
arr = arr[1:-1]
if arr == '':
arr = deque()
else:
arr = list(map(str, arr.split(',')))
arr = deque(arr)
for ch in implement:
if ch == 'R':
if is_reverse == False:
is_reverse = True
else:
is_reverse = False
else:
if arr:
if is_reverse == True:
arr.pop()
else:
arr.popleft()
else:
print('error')
break
else:
if is_reverse == True:
arr.reverse()
print('[' + ','.join(map(str, arr)) + ']')
caucsejunseo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
μ 체λ₯Ό λ€μ§μ§ μκ³ reversed μ΄μ©ν΄μ front rearλ‘ μ κ·Όνλ λ²! '[,]' κ°μ λ¬Έμμ΄ μ²λ¦¬νλ λ²! λ± μλ‘μ΄ λ°©λ² λ§μ΄ λ°°μ°κ² λ λ¬Έμ λ€μ. λ¬Έμμ΄μ νμ λ²λ² μ΄κ² λλκ±° κ°μμ..
C
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <stdbool.h>
#define MAX 100001
int arr[MAX];
int main()
{
int T;
scanf("%d", &T);
while (T--)
{
char p[MAX];
int n;
char input[700002];
scanf("%s", p);
scanf("%d", &n);
scanf("%s", input);
int front = 0 , rear = n - 1;
bool reversed = false, error = false;
int idx = 0;
char* token = strtok(input, "[,]");
while (token != NULL)
{
arr[idx++] = atoi(token);
token = strtok(NULL, "[,]");
}
for (int i = 0; p[i]; i++)
{
if (p[i] == 'R')
{
reversed = !reversed;
}
else if(p[i])
{
if (front > rear)
{
error = true;
break;
}
if (!reversed)
front++;
else
rear--;
}
}
if (error)
{
printf("error\n");
}
else
{
printf("[");
if (!reversed)
{
for (int i = front; i < rear+1; i++)
{
printf("%d", arr[i]);
if (i < rear)
{
printf(",");
}
}
}
else
{
for (int i = rear; i >= front; i--)
{
printf("%d", arr[i]);
if (i > front)
{
printf(",");
}
}
}
printf("]\n");
}
}
return 0;
}
π λ¬Έμ λ§ν¬
AC
βοΈ μμλ μκ°
20λΆ
β¨ μλ μ½λ
μλ μ½λ
μ΄ λ¬Έμ λ ν μ€νΈ μΌμ΄μ€λ§λ€ λ°°μ΄μ΄ μ£Όμ΄μ§κ³ , κ·Έ λ°°μ΄μ μ£Όμ΄μ§ λͺ λ Ήμ λ°λΌ λ€μ§κ±°λ λ²λ¦¬λ λ¬Έμ μ λλ€.
μ²μμλ λ°°μ΄μ μ§μ λ£κ³
reverseν¨μλ‘ μ§μ λ€μ§μκΉ νλ€κ°, μκ° μ΄κ³Όκ° λ κ² κ°μ λ€λ₯Έ λ°©λ²μ μ°Ύμμ΅λλ€.revλΌλ λ³μλ₯Ό λ°λ‘ μ μΈν΄μ, λ€μ§λ λͺ λ Ήμ΄ λ€μ΄μ€λ©΄rev = not revμ ν΅ν΄ νμλ§ νκ² νμ΅λλ€. κ·Έλ° λ€μarrμ΄Trueμ΄λ©΄popμ νκ³ (λ€μ§μ΄μ‘μΌλ©΄ μΌμͺ½μ΄ μ€λ₯Έμͺ½μ΄ λ¨!), μλλ©΄popleftλ₯Ό νκ² ν΄μ κ²°κ³Όμ μΌλ‘ O(1)λ§μ λ²λ¦¬λ λμμ ν μ μμμ΅λλ€.μ΄λ κ² μ°μ°μ νκ³ , λ§μ§λ§μ λ€μ§μ΄μ‘λμ§ νμΈνμ¬ μνμ λ§κ²
dequeλ₯Ό μΆλ ₯νμ΅λλ€.μ²μμ ν λ λΉ λ°°μ΄ μ²λ¦¬λ₯Ό μ νκ³ νμλλ μλ¬κ° λ΄μ΅λλ€ γ γ .. μ΄ μ κ³ λ €ν΄μ λ¬Έμ λ₯Ό νμ΄μΌν©λλ€.
π μλ‘κ² μκ²λ λ΄μ©