题解 | #参数解析#

参数解析

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");
}

全部评论

相关推荐

2024-12-27 23:45
已编辑
三江学院 Java
程序员牛肉:死局。学历+无实习+项目比较简单一点。基本就代表失业了。 尤其是项目,功能点实在是太假了。而且提问点也很少。第一个项目中的使用jwt和threadlocal也可以作为亮点写出来嘛?第二个项目中的“后端使用restful风格”,“前端采用vue.JS”,“使用redis”也可以作为亮点嘛? 项目实在是太简单了,基本就是1+1=2的水平。而你目标投递的肯定也是小厂,可小厂哪里有什么培养制度,由于成本的问题,人家更希望你来能直接干活,所以你投小厂也很难投。基本就是死局,也不一定非要走后端这条路。可以再学一学后端之后走测试或者前端。 除此之外,不要相信任何付费改简历的。你这份简历没有改的必要了,先沉淀沉淀
点赞 评论 收藏
分享
西松屋:说明原部门有机会把
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务