2、奇特密码
题目 鸡哥的奇特密码
思路分析
任意连续的两个L会合成一个L
LLL → LL → L
其实只要是连续的L都会变成一个L
所以只需要输出第一个L
如何判断是不是第一个L ——左边没元素或者左边是Q
代码实现
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
int main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
string s;cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]=='L' && (i-1<0 || s[i-1]=='Q'))
cout<<'L';
if(s[i]=='Q')
cout<<'Q';
}
return 0;
}
💬 评论