7-6 加密信息---easy version(不会)

360 篇文章 3 订阅
138 篇文章 1 订阅

给定一个长度为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;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_努力努力再努力_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值