keng

#include 
#include 
#include 
#include 
using namespace std;


vector ExtractNumFromString(string& s)
{
	int numStart;
	int numEnd;
	vector ret;
	for(int i = 0;i=0 && s[i] <=9))
		{
			numStart = i;
		}
		else if((s[i] == ' ' && (s[i + 1] >='0' && s[i + 1] <='9')))
		{
			numStart = i + 1;
		}
		else if((s[i] >='0' && s[i] <='9') && (s[i+1] == ' ' || s[i+1] == '\0'))
		{
			numEnd = i;
			int num = 0;
			for(int j = numStart;j<=numEnd;j++)
				num = num*10 + (s[j]-'0');
			ret.push_back(num);
		}
		else if((s[i]>='a' && s[i]<='z') || (s[i]>='A' && s[i]<='Z') || (s[i]>='0' && s[i]<='9') )
		{
			continue;
		}
		
		
	}

	return ret;
}


int main()
{
	ifstream inFile;
	inFile.open("data.txt");
	vector strVec;
	
	string s;
	vector numVec;
	while(getline(inFile,s))
	{
		numVec = ExtractNumFromString(s);
		for(vector::iterator it = numVec.begin();it != numVec.end();it++)
		{
			cout<<*it<::iterator it = strVec.begin();it != strVec.end();it++)
		outFile<<*it<

你可能感兴趣的:(Exercise)