求助!!为什么在本地编译器无法自动结束输入
查看原帖
求助!!为什么在本地编译器无法自动结束输入
683726
brpaddle楼主2022/3/30 21:39

如题。

在编译器无法正常结束,但是在在线IDE能输出正确答案。求dalao救救,谢谢!

另外,我看题解里面大佬们都是只有if(ch==']')才返回字符串s。如果输入字符串是没有进行压缩过的,即没有']',为什么能输出正确答案呀!?

#include<iostream>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<vector> 
#include<set> 
#include<string>
using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

string read()
{
	int k;
	string s="",str;//s为最终答案,str为解压缩之后的数组
	char ch;
	
	while(cin>>ch)
	{
		if(ch=='[')
		{
			cin>>k;
			str=read();
			while(k--)
				s+=str;
		}
		else if(ch==']')
		{
			return s;		
		}
		else
		{
			s+=ch;
		}
		
	}	
		
} 


int main()
{
	cout<<read();
	return 0;
} 
2022/3/30 21:39
加载中...