#46353: 裹著心的光


1121226@stu.wghs.tp.edu.tw (Arthur✨EC)

學校 : 臺北市私立薇閣高級中學
編號 : 252772
來源 : [60.248.154.139]
最後登入時間 :
2025-08-21 12:59:45

#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    string result="";
    string current="";
    bool leftToRight=true; // 一開始從左往右讀
    for(int i=0;i<s.length();i++){
        if(s[i]=='+'||s[i]=='-'){
            // 處理當前累積的字串
            if(leftToRight){
                result+=current;
            }
            else{
                // 從右到左,需要反轉
                reverse(current.begin(), current.end());
                result+=current;
            }
            // 清空當前字串並設定新的讀取方向
            current="";
            leftToRight=(s[i]=='+');
        }
        else{
            // 一般字元,加入當前字串
            current+=s[i];
        }
    }

    // 處理最後剩餘的字串
    if(leftToRight){
        result += current;
    } else {
        reverse(current.begin(), current.end());
        result += current;
    }

    cout << result << endl;

    return 0;
}