其他分享
首页 > 其他分享> > CCF CSP认证201403-3 命令行选项

CCF CSP认证201403-3 命令行选项

作者:互联网

201403-3 命令行选项

题目

在这里插入图片描述

思路

0分代码,路过的大佬求指正orz。

代码

#include<iostream>
#include<cstring>
#include<string>
#include<map>
#include<vector>
using namespace std;
int pra[30]={0};

void my_split(string cmd,vector<string> &str){
    int s=3;
    while(s<cmd.size()){
        int t=cmd.find(" ",s);
        if(t==string::npos) t=cmd.size();
        string temp=cmd.substr(s,t-s);
        str.push_back(temp);
        s=t+1;
    }
}

map<string,string> anylize(vector<string> str){
    map<string,string> ans;
    for(int i=0;i<str.size();i++){
        string choice=str[i];
        if(choice[0]!='-'||choice.size()!=2) return ans;
        int t=choice[1]-'a';
        switch(pra[t]){
            case 0: return ans;
            case 1: ans[choice]="NONE";break;
            default : if(i+1<str.size()) ans[choice]=str[i+1];i++;
        }
    }
    return ans;
}

int main(){
    string pras;
    cin>>pras;
    for(int i=0;i<pras.size();i++){
        if(pras[i]==':') pra[pras[i-1]-'a']=2;
        else pra[pras[i]-'a']=1;
    }
    int n;
    cin>>n;
    getchar();
    for(int i=1;i<=n;i++){
    	string cmd;
        getline(cin,cmd);
        vector<string> str;
        my_split(cmd,str);
        map<string,string> ans=anylize(str);
        cout<<"Case "<<i<<":";
        //if(ans.size()==0) {cout<<" "<<endl;continue;}
        for(map<string,string>::iterator it=ans.begin();it!=ans.end();it++){
            cout<<" "<<it->first;
            if(it->second!="NONE") cout<<" "<<it->second;
        }
        cout<<endl;
    }
    return 0;
}

标签:201403,include,cout,int,cmd,str,ans,CCF,CSP
来源: https://blog.csdn.net/weixin_43944910/article/details/99763164