打开题目链接

题意:输入一个字符串,用,或;分隔输出字符串和整数(不含前导0和浮点数)

ACcode:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
string s,digit,seq,temp;
int main()
{
cin>>s;
for(int i=0; i<s.length(); i++)
if(s[i] == ',' || s[i] == ';')
s[i] = ' ';
bool flag = false;
s+=" ";
//init
temp = digit = seq = "";
for(int i=0; i<s.length(); i++)
{
if(s[i] == ' ')
{
if(flag || (temp[0] == '0' && temp.length()>1) || temp.length() == 0)
{
seq+=","+temp;
}else
{
digit +=","+temp;
}
temp ="";
flag = false;
continue;
}
if(s[i]<'0' || s[i]>'9')
flag = true;
temp+=s[i];
}
if(digit != "")
{
digit.erase(0,1);
cout<<'"'<<digit<<'"'<<endl;
}else
cout<<"-"<<endl;
if(seq !="")
{
seq.erase(0,1);
cout<<'"'<<seq<<'"'<<endl;
}else
cout<<"-"<<endl; return 0;
}

  

05-11 15:38
查看更多