竞赛讨论区 > 示例通过但是零分
头像
_怜_
编辑于 03-30 19:07 河北
+ 关注

示例通过但是零分

#include<bits/stdc++.h>

using namespace std;

int main()

{

int T;

cin>>T;

for(int i=0;i<T;i++)

{

int n;

string s1, s2;

cin>>n;

cin.ignore();

string s;

cin>>s;

int shuru = 1; // 1表示右侧,-1表示左侧

for(int j = 0; j < n; j++)

{

if(s[j] == '!')

{

shuru = -shuru;

}

else if(s[j] == '-')

{

if(shuru == 1)

{

if(!s2.empty()) s2.pop_back();

}

else // shuru == -1

{

if(!s1.empty()) s1.pop_back();

}

}

else if(s[j] >= 'a' && s[j] <= 'z')

{

if(shuru == 1)

{

s2.push_back(s[j]);

}

else

{

s1.push_back(s[j]); // 注意:这里是逆序存储

}

}

}

reverse(s1.begin(), s1.end()); // 反转得到正确顺序

if(s1.empty() && s2.empty())

{

cout << "Empty" << endl;

}

else

{

cout << s1 << s2 << endl;

}

}

return 0;

}

全部评论

(0) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐