参数解析

#include<iostream>
#include<vector>
#include<string>
using namespace std;


void solve(char *str)
{
    vector<string> v;
    char tmp[100];
    int tmpcount = 0;
    for(int i=0; str[i]!='\0'; i++)
    {
        if(str[i]==' ' || str[i]=='\t' )
        {
            if(i>0 && str[i-1]!=' ')
            {
                tmp[tmpcount] = '\0';
                tmpcount = 0;
                string stmp = tmp;
                v.push_back(stmp);
            }
        }
        else
        {
            tmp[tmpcount++] = str[i];
        }
    }
    if(tmpcount>0)
    {
        tmp[tmpcount]='\0';
        string stmp = tmp;
        v.push_back(stmp);
    }

    cout<<v.size()<<endl;
    for(int i=0; i<v.size(); i++)
        cout<<v[i]<<endl;
}

int main()
{
    char buf[100];
    cin.get(buf,100,'\n');

    solve(buf);


    return 0;
}

  

posted @ 2016-12-29 22:46  Hardsoftware  阅读(156)  评论(0编辑  收藏  举报