#41921:


1121232@stu.wghs.tp.edu.tw (Ian911436)

學校 : 臺北市私立薇閣高級中學
編號 : 258883
來源 : [60.248.154.139]
最後登入時間 :
2024-10-30 13:05:08
c621. Reverse this and that !! -- it's david | From: [60.248.154.143] | 發表日期 : 2024-09-10 14:54

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    string str;
    while (cin >> str)
    {
        vector<string>alpha;
        vector<char>num;
        string tmp = "";
        for (int i = 0; i<str.length(); i++)
        {
            if (!isalpha(str[i]))
            {
                if (tmp != "")
                {
                    reverse(tmp.begin(), tmp.end());
                    alpha.push_back(tmp);
                    tmp = "";
                }
                num.push_back(str[i]);
            }
            else
            {
                tmp += str[i];
                if (i == str.length()-1)
                {
                    reverse(tmp.begin(), tmp.end());
                    alpha.push_back(tmp);
                }
            }
        }
        reverse(num.begin(), num.end());
        for (int i = 0; i<str.length(); i++)
        {
            if (!isalpha(str[i]))
            {
                cout << num[0];
                num.erase(num.begin());
            }
            else
            {
                cout << alpha[0];
                i += alpha[0].length()-1;
                alpha.erase(alpha.begin());
            }
        }
        cout << "\n";
    }
}
 
ZeroJudge Forum