有一些字符,陆续来到,根据到来的字符有以下4种操作: 如果刚来的字符是大写字母,就放到队列的前面; 如果刚来的字符是小写字母,就放到队列的后面; 如果刚来的字符是数字’0’到’9’,就删除队列的前面1个字母; 如果刚来的字符是其他字符,就删除队列的后面1个字母; 注:如果队列中没有字母,就不会删除任何东西。 请编程输出最后的队列中的字母。
输入格式 第一行:一个由字符串,长度范围在[1,1000]。
输出格式 一行由字母组成字符串。(可能是空串)
输入/输出例子1 输入:
aeBbD1@
输出:
Bae
#include<bits/stdc++.h>
using namespace std;
char a[3005];
string s;
int n,top,bottom;
int main()
{
cin>>s;
top=2000;
bottom=2000;
for(int i=0;i<s.size();i++){
/* a[bottom]=s[i];
if(a[bottom]==a[top]&&top!=bottom)
top++;
else bottom++;*/
if(s[i]>='A' and s[i]<='Z')
a[--top]=s[i];
else if(s[i]>='a' and s[i]<='z')
a[++bottom]=s[i];
else if(s[i]>='0' and s[i]<='9' )
{
if(top!=bottom)
top++;
}
else
if(top!=bottom)
bottom--;
}
//int ans=top-bottom;
for(int i=top;i<bottom;i++)
{
cout<<a[i];
}
return 0;
}
是哪里加多了一次或者减多了一次?
求解