题解 | #参数解析#

参数解析

http://www.nowcoder.com/practice/668603dc307e4ef4bb07bcd0615ea677

临时拼凑,看看其它方法。

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <map>
#include <vector>

using namespace std;
/*
xcopy /s c:\\ d:\\
4
xcopy
/s
c:\\
d:\\

 */
static const int MAX_STR_NUM=1000;
static const int MAX_STR_LEN=1000;

int main(void)
{
    int ret =0;
    vector<string> vc_str;
    int muti_flag=0;
    string tmp;
    int arg_num = 0;

    while (1)
    {
        char org_str[MAX_STR_LEN]={0};
        ret = scanf("%s",org_str);
        if(ret == EOF){
            break;
        }
        //cout<<"get str:"<<org_str<<endl;
        if(muti_flag==0)        {
            if(org_str[0]=='"')            {
                muti_flag = 1;
                tmp.append(org_str+1);
                if(tmp[tmp.size()-1]=='"'){
                    tmp[tmp.size()-1] = 0;
                    muti_flag = 0;
                    vc_str.push_back(tmp);
                    //cout<<"push_back:"<<tmp.c_str()<<endl;
                    arg_num++;
                    tmp.clear();
                }
            }else{
                tmp.append(org_str);
                vc_str.push_back(tmp);
                //cout<<"push_back:"<<tmp.c_str()<<endl;
                arg_num++;
                tmp.clear();
            }
        }
        else{//muti_flag==1
            tmp.append(" ");
            tmp.append(org_str);
            //int strLen= strlen(org_str);
            if(tmp[tmp.size()-1]=='"')
            {
                tmp[tmp.size()-1] = 0;

                muti_flag =0;
                vc_str.push_back(tmp);
                //cout<<"push_back:"<<tmp.c_str()<<endl;
                arg_num++;
                tmp.clear();
            }
        }
    }
    cout<<vc_str.size()<<endl;
    for(auto it=vc_str.begin();it!=vc_str.end();it++){
        cout<<it->c_str()<<endl;
    }

    system("pause");
}

全部评论

相关推荐

lingo12:1.最好加个业务项目,大部分面试官工作以后会更偏重业务 2.实习部分描述一般般,可能hr看到会觉得你产出不够不给你过简历 3.蓝桥杯这些大部分人都有的,不如不写,反而减分项。
点赞 评论 收藏
分享
28小凳也想实习:项目不用一个业务一个轮子吗,刷牛客好多人说要一业务一轮子
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务