求助
查看原帖
求助
1409448
WXY_ShiXiaoJi楼主2024/8/4 13:03

思路是栈,不会做换行,所以用了之前做的类似题目的程序(有改动)。

求住

#include<bits/stdc++.h>
using namespace std;
stack<char>s;
string str;
char ans[250];
int main(){
	getline(cin,str);
	int len=str.length();
	for(int i=0;i<len;i++){
		switch(str[i]){
			case'<':if(!s.empty()) s.pop(); break;	
			default:s.push(str[i]);
		}
	}
	int l=s.size();
	for(int i=0;i<l;i++){
		ans[i]=s.top();
		s.pop();
	}
	for(int i=l-1;i>=0;i--){
		cout<<ans[i];
	}
	
	return 0;
}
2024/8/4 13:03
加载中...