算法流程:枚举每个题目,判断该题目之前是否出现过,若出现过则跳过该题目,时间复杂度O(n^2),空间复杂度O(n)。
实现核心功能的类:
1 vector<string> program; 2 vector<string> different_program; 3 class Solver{ 4 bool have_same_program(string p){ 5 for(int i=0;i<different_program.size();i++){ 6 if(p==different_program[i]) return true; 7 } 8 return false; 9 } 10 public: 11 void solve(){ 12 different_program.clear(); 13 for(int i=0;i<program.size();i++){ 14 if(have_same_program(program[i])) continue; 15 different_program.push_back(program[i]); 16 } 17 } 18 }mysolver;