zoj 1175 Word Process Machine

zoj 1175 Word Process Machine,第1张

zoj 1175 Word Process Machine
#include <iostream>#include <string>#include <cstdio>#include <algorithm>using namespace std;string Source, Code, Result;void Init(){    Source.clear();    Code.clear();    Result.clear();}int main(){    int nCase;    int n;    int front;    string input;    cin>>nCase;    while(nCase--){        Init();        cin>>n;        cin.ignore();        for(int i = 0; i < n; i++){ getline(cin, input); if(input.size()){     Source += input; }        }        while(cin>>input){ for(int i = 0; i < input.size(); i++){     if(input[i] == ' ') input.erase(i, 1);     if(i && input[i] == 'R' && input[i - 1] == 'R') input.erase(i - 1, 2); } Code += input; if(input[input.size() - 1] == '#') break;        }        front = 0;        for(int i = 0; i < Code.size() - 1; i++){ if(!Source.size()) break; if(Code[i] == 'R'){     if(!front) front = Source.size() - 1;     else front = 0; }else if(Code[i] == 'G'){     int j = i;     while(Code[j] == 'G' && (j - i) < Source.size()) j++;     if(!front){         string s(Source, 0, j - i);         Result += s;         Source.erase(0, j - i);     }else {         string s(Source, Source.size() - (j - i), j - i), ss;         reverse(s.begin(), s.end());         Result += s;         Source.erase(Source.size() - 1, j - i);     }     i = j - 1; }        }        for(int i = 0; i < Result.size(); i++){ if(i && !(i % 80)) cout<<endl; cout<<Result[i];        }        if(Result.size() && !(Result.size() % 80) && nCase){ cout<<endl;        }else if(nCase) cout<<endl<<endl;    }    return 0;}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4907949.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-12
下一篇 2022-11-12

发表评论

登录后才能评论

评论列表(0条)

保存