CCF CSP 命令行选项

it2025-04-17  5

题意

略。你能看到我写的题意就是一定知道题到底是个啥玩意。

讲解

你说让我怎样做,我就要去那样做的题目。难度不是太大。 细节处需要注意。

代码

#include <bits/stdc++.h> using namespace std; int main(void) { string s; int n; vector<char> Y; vector<char> N; map<char, string> O; cin >> s; cin >> n;//有几条命令 getchar(); /*对开头第一行能接受的指令集进行处理。 对能接受参数的指令 不能接受参数的指令进行分化处理*/ for (string::size_type i = 0; i < s.length(); i ++) { if (s[i+1] == ':')//后面有:就是能够接受参数的指令 { Y.push_back(s[i]); i ++; continue; } //没有:的指令就是不能接受参数的指令 N.push_back(s[i]); } //对接受的命令进行处理。输出 for (int i = 0; i < n; i ++) { string t; getline(cin, s); stringstream ss(s); ss >> t; while (ss >> t) { string tt; if (t.length() == 2) { if (t[0] == '-') { if (find(Y.begin(), Y.end(), t[1]) != Y.end()) { if (ss.eof())//需要参数的命令在结尾可是已经读取不到后面的参数了,命令错误 break;//跳出 ss >> tt; O[t[1]] = tt; } else if (find(N.begin(), N.end(), t[1]) != N.end()) { O[t[1]] = ""; } else//不存在的命令的格式的错误 break; } else { break; } } else break; } cout << "Case " << i+1 << ": "; for (map<char, string>::iterator it = O.begin(); it != O.end(); it ++) { if ((*it).second == "") cout << "-" << (*it).first << " "; else cout << "-" <<(*it).first << " " << (*it).second << " "; } cout<< endl; O.clear(); } return 0; }

欢迎各位大神交流指导:联系QQ:1364388975

最新回复(0)