求助!
  • 板块题目总版
  • 楼主yaoyunhan181
  • 当前回复4
  • 已保存回复4
  • 发布时间2020/7/21 22:53
  • 上次更新2023/11/6 22:38:03
查看原帖
求助!
144383
yaoyunhan181楼主2020/7/21 22:53

不知道怎么回事。。。

#include<bits/stdc++.h>
#include<strstream>
using namespace std;
string a;
int n;
int i,j;
int main()
{
	cin>>n>>a;
	for(i=0;i<=a.size()-1;i++)
	{
		if(a[i]!='-')
		{
			cout<<a[i]; 
		}
		else
		{
			string s=NULL;
			int ls=0;
			for(j=1;true;j++)
			{
				if(a[i-j]==',' || i-j<0)
				{
					break;
				}
				else
				{
					s+=a[i-j];
				}
			}
			reverse(s.begin(),s.end());
			strstream sin;
			sin<<s;
			sin>>ls;
			s.clear();
			int rs=0;
			for(j=1;true;j++)
			{
				if(a[i+j]==',' || i+j>a.size())
				{
					break;
				}
				else
				{
					s+=s[i+j];
				}
			}
			sin<<s;
			sin>>rs;
			for(j=ls+1;j<=rs-1;j++)
			{
				cout<<","<<j;
			}
			cout<<",";
		}
	}
}

报错:

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_S_construct null not valid

--------------------------------
Process exited after 19.25 seconds with return value 3
2020/7/21 22:53
加载中...