leetcode输入[1,2,3,4] 将数字分隔方法
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;
typedef long long ll;
const int mod=1e9+7;
typedef unsigned long long ull;
//typedef __int128 LL;
const double eps=10e-8;
const double pi=acos(-1.0);
#define between(x,a,b)(a<=x && x<=b)
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3f;
typedef pair<ll,ll> pII;
typedef pair<int,int> pii;
typedef pair<int,ll> piI;
int a[MAXN];
int main()
{
#ifndef ONLINE_JUDGE
freopen("1.in", "r", stdin);
freopen("debug.out", "w", stdout);
#endif
string s;
cin>>s;
//getline(cin,s);//输入带空格
int len=s.size();
for(int i=0;i<len;i++)
{
if(s[i]=='['||s[i]==','||s[i]==']')s[i]=' ';
}
istringstream is(s);
int i=0;
int str;
int cnt=0;
while(is>>str)
{
cnt++;
a[++i]=str;
//a[++i]=stoi(str) string str // 将字符串转化为数字
}
for(int j=1;j<=cnt;j++)printf("%d\n",a[j]);
return 0;
}