题目链接:
命令行选项
题目大意:
中文题目,不解释!!!
记住仔细读题就好!!!
解题思路:
一如既往的模拟题,这里需要灵活利用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;
}