给定一个长度为n(n<=5×10
5
)的加密字符串S,解密方式如下:
1.初始时字符串T为空.
2.从头遍历S字符串,令i=1,2,3…,n, 若S的第i个字符是R,那么翻转T字符串,否则将该字符加入T串中.
那么T串就是最终解密完毕的字符串.
输入格式:
输入一个加密字符串S
S
输出格式:
输出最后解密完毕的字符串T
T
输入样例1:
ozRnonnoe
输出样例1:
zononnoe
样例解释:
● 初始时T为空z加入T中
● 将z加入T中, 此时T是z
●将o加入T中, 此时T是zo
●翻转T,此时T是oz
●将n加入T中, 此时T是zon
●将o加入T中, 此时T是zono
●将n加入T中, 此时T是zonon
●将n加入T中, 此时T是zononn
●将o加入T中, 此时T是zononno
●将e加入T中, 此时T是zononnoe
输入样例2:
在这里给出一组输入。例如:
hellospaceRhellospace
输出样例2:
在这里给出相应的输出。例如:
ecapsollehhellospace
两种方法写的,全不对,心态崩了
reverse函数超时
deque答案错误
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<cctype>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
using namespace std;
int main(){
deque<char>de;
string s,t;
cin>>s;
int flag=0;
for(int i=0;i<s.size();i++){
if(s[i]=='R'){
flag=1;
}
if(!flag&&s[i]!='R'){
de.push_back(s[i]);
}
else if(flag&&s[i]!='R'){
de.push_front(s[i]);
}
}
if(flag==0){
while(!de.empty()){
cout<<de.front();
de.pop_front();
}
}
else{
while(!de.empty()){
cout<<de.back();
de.pop_back();
}
}
return 0;
}
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<stack>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<cctype>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
using namespace std;
int main(){
string s,t;
cin>>s;
t="";
for(int i=0;i<s.size();i++){
if(s[i]!='R'){
t+=s[i];
}
else{
reverse(t.begin(),t.end());
}
}
cout<<t;
return 0;
}