傻逼题,要是考试只能得0分。。
提供几组傻逼数据,这要是在真实的生活中一定是错的。。。
还是要好好读题吧,全凭自己的感觉就得0分
albw:x
4
ls -a docu
Case 1: -a
ls -w -w
Case 2: -w -w
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define pb(x) push_back(x)
#define cls(x, val) memset(x, val, sizeof(x))
#define fi first
#define se second
#define mp(x, y) make_pair(x, y)
#define inc(i, l, r) for(int i=l; i<=r; i++)
const int inf = 0x3f3f3f3f;
const int maxn = 2000+10;
bool have[maxn];
bool exist[maxn];
struct Node{
string s;
string var;
bool prin;
}node[26];
int n;
vector<string> split;
vector<string> process(char *s){
int st = 0;
vector<string> temp;
string t;
int len = strlen(s);
for(int i=0; i<len; i++){
if(s[i] == ' '){
t = "";
for(int j=st; j<i; j++){
t+=s[j];
}
temp.push_back(t);
st = i+1;
}
}
t = "";
for(int j=st; j<len; j++){
t+=s[j];
}
temp.push_back(t);
return temp;
}
int main(){
ios::sync_with_stdio(false);
char op[300];
scanf("%s", op);
int len = strlen(op);
for(int i=0; i<len; i++){
if(op[i]>='a'&&op[i]<='z'){
exist[op[i]-'a'] = true;
if(i+1<len && op[i+1] == ':'){
have[op[i]-'a'] = true;
i++;
}
}
}
int kase = 1;
scanf("%d", &n);
getchar();
while(n--){
gets(op);
for(int i=0; i<26; i++) node[i].prin = false;
split = process(op);
int sz = split.size();
// for(int i=0; i<sz; i++){
// printf("%s ", split[i].c_str());
// }
for(int i=1; i<sz; i++){
string temp = split[i];
if(temp[0] == '-'){
int c = temp[1]-'a';
if(!exist[c]) break;
if(have[c] == true){
if(i==sz-1) break;
else {
node[c].prin = true;
node[c].var = split[i+1];
}
i++;
}
else{
node[c].prin = true;
}
}
else break;
}
//cout<<"Case "<<kase++<<":";
printf("Case %d:", kase++);
for(int i=0; i<26; i++){
if(node[i].prin){
//cout<<" -"<<char(i+'a');
printf(" -%c", char(i+'a'));
if(have[i]){
//cout<<" "<<node[i].var;
printf(" %s", node[i].var.c_str());
}
}
}
printf("\n");
}
return 0;
}
原文地址:https://www.cnblogs.com/babydragon/p/11715731.html
时间: 2024-11-01 20:30:02