201403-3 ccf --命令行选项(stringstream活用)

命令行选项题:用Stringstream解题
博客围绕命令行选项题目展开,强调仔细读题。解题思路是利用STL的Stringstream字符串流,这是一道模拟题,还推荐参考相关博客学习C++之Stringstream,并给出了AC代码。

题目链接:
命令行选项

题目大意:
中文题目,不解释!!!
记住仔细读题就好!!!

解题思路:
一如既往的模拟题,这里需要灵活利用STL之Stringstream字符串流,然后就豁然开朗了!!
可以参考这个博客学习!
C++之Stringstream

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>


using namespace std;

int type[26];
string argu[26];


int main(){
    string p;
    cin>>p;
    for(int i=0; i<p.size(); ++i){
        int tmp;
        if(p[i]==':'){
            type[tmp] = 2;
        }else{
            tmp = p[i] - 'a';
            type[tmp] = 1;
        }
    }

    int n;
    cin>>n;
    cin.get();
    for(int i=1; i<=n; ++i){
        for(int x=0; x<26; ++x) argu[x]="";
        string temp;
        getline(cin,temp);
        stringstream ss(temp);
        ss >> temp;
    //  cout<<temp<<endl;
        while(ss>>temp){
            if(temp[0]=='-'){
                int tmp = temp[1]-'a';
                if(type[tmp]==0) break;
                else if(type[tmp]==1){
                    argu[tmp] = " ";
                }else if(type[tmp]==2){
                    if(ss.eof()) break;
                    ss >> temp;
                    argu[tmp] = temp;
                }
            }else break;
        }
        cout<<"Case "<<i<<":";
        for(int j=0; j<26; ++j){
            if(type[j]==1 && argu[j] !=""){
                cout<<" -"<<char(j+'a');
            }
            if(type[j]==2 && argu[j] !=""){
                cout<<" -"<<char(j+'a')<<" "<<argu[j]; 
            }
        }
        cout<<endl;
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值