码迷,mamicode.com
首页 > 其他好文 > 详细

参数解析

时间:2016-12-30 01:55:42      阅读:200      评论:0      收藏:0      [点我收藏+]

标签:amp   back   using   push   void   ret   div   cto   i++   

#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;
}

  

参数解析

标签:amp   back   using   push   void   ret   div   cto   i++   

原文地址:http://www.cnblogs.com/hardsoftware/p/6235068.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!