题解 | #参数解析#

参数解析

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

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    string str;
    while(getline(cin,str))
    {
        vector<string>vec;
        int i=0;
        while(i<str.size())
        {
            string s;
            bool f=false;
            if(str[i]=='"')
            {
                i++;
                while(str[i]!='\0'&&str[i]!='"')
                {
                    s.push_back(str[i]);
                    f=true;
                    i++;
                }
            }
            else
            {
                while(str[i]!='\0'&&str[i]!=' ')
                {
                    s.push_back(str[i]);
                    f=true;
                    i++;
                }
            }
            i++;
            if(f){
                vec.push_back(s);
            }
        }
        cout<<vec.size()<<endl;
        for(int c=0;c<vec.size();c++)
        {
            string outstr=vec[c];
            int i=count(outstr.begin(),outstr.end(),'"');
            if(i>0)
            {
                int j=0;
                string ts;
                while(outstr[j]!='\0')
                {
                    if(outstr[j]!='"')
                    {
                        ts.push_back(outstr[j]);
                    }
                    j++;
                }
                outstr=ts;
            }
            cout<<outstr<<endl;
        }
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-09 11:30
找工作7个月,投了7000封,3段世界五百强实习,才有一个offer,牛油们肯定比我强吧
码农索隆:不对不对不对,实习经历这么厉害,简历也没少投,问题出在哪呢
点赞 评论 收藏
分享
frutiger:逆天,我家就安阳的,这hr咋能说3k的,你送外卖不比这工资高得多?还说大厂来的6k,打发叫花子的呢?这hr是怎么做到说昧良心的话的
找工作时遇到的神仙HR
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
今天 12:10
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务