본문 바로가기
Algorithm(CodeTree, C++)/문자열

[코드트리] 규칙에 따라 밀기 C++

by kurooru 2024. 6. 23.

#include <iostream>
#include <string>
using namespace std;

void push_left(string &s) {
    s = s.substr(1) + s.substr(0, 1);
}

void push_rignt(string &s) {
    int s_len = s.length();
    s = s.substr(s_len - 1) + s.substr(0, s_len - 1);
}

int main() {
    // input
    string a, order;
    cin >> a >> order;

    int order_len = order.length();
    for (int i = 0; i < order_len; i++) {
        if (order[i] == 'L') {
            push_left(a);
        } else if (order[i] == 'R') {
            push_rignt(a);
        }
    }

    cout << a;
    return 0;
}

 

 

코드트리 | 코딩테스트 준비를 위한 알고리즘 정석

국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.

www.codetree.ai