1. 程式人生 > >識別字符串中的整數並轉換為數字形式

識別字符串中的整數並轉換為數字形式

int f(string s,int*a)
{
	int count=0;
	int n=0;
	bool isnumber=false;
	for(int i=0;i<s.size();i++)
	{
		if(isdigit(s[i]))
		{
			n=n*10+s[i]-'0';
			isnumber=true;
			if(i==s.size()-1)
			{
				a[count++]=n;
			}
		}
		else
		{
			if(isnumber) 
			{
				a[count++]=n;
				n=0;isnumber=false;
			}
		}
	}
	return count;
}