Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- vector<string> find_basic_commands(vector<string>& logs) {
- sort(logs.begin(), logs.end(), [](const string &a, const string &b) {
- return a.length() < b.length();
- });
- vector<string> basic_commands;
- for (const string& log : logs) {
- bool is_substring = false;
- for (const string& cmd : basic_commands) {
- if (log.find(cmd) != string::npos) {
- is_substring = true;
- break;
- }
- }
- if (!is_substring) {
- basic_commands.push_back(log);
- }
- }
- return basic_commands;
- }
- int main() {
- int C;
- cin >> C;
- cin.ignore();
- for (int case_idx = 1; case_idx <= C; ++case_idx) {
- int N;
- cin >> N;
- cin.ignore();
- vector<string> logs(N);
- for (int i = 0; i < N; ++i) {
- getline(cin, logs[i]);
- }
- vector<string> result = find_basic_commands(logs);
- cout << "Case #" << case_idx << ": " << result.size();
- for (const string& cmd : result) {
- cout << " " << cmd;
- }
- cout << "\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement