Huawei_test_2.jpgHuawei_test_3.jpg

  • 字符串提取
  • 字符串筛选
  • 字符串匹配 ```cpp

    include

    include

    include

    using namespace std;

//legal word dictionary string dictionary = “xX0123456789abcdefABCDEF”;

bool judge_indictionary(string input_str) { for (int i = 0; i < input_str.size(); i++) { if (dictionary.find(input_str[i]) == -1) { return false; } } return true; }

int main() { string key_word; while (cin >> key_word) { string temp; vector vec_word; vector vec_addr; vector vec_mask; vector vec_val;

  1. int index_f = 0;
  2. int index_b = 0;
  3. while (cin >> temp)
  4. {
  5. //pick usefull information
  6. index_f = 0;
  7. index_b = temp.find_first_of('[');
  8. vec_word.push_back(temp.substr(0, index_b));
  9. index_f = temp.find_first_of('=');
  10. index_b = temp.find_first_of(',');
  11. vec_addr.push_back(temp.substr(index_f + 1, (index_b - index_f - 1)));
  12. temp.erase(index_f, (index_b - index_f + 1));
  13. index_f = temp.find_first_of('=');
  14. index_b = temp.find_first_of(',');
  15. vec_mask.push_back(temp.substr(index_f + 1, (index_b - index_f - 1)));
  16. temp.erase(index_f, (index_b - index_f + 1));
  17. index_f = temp.find_first_of('=');
  18. index_b = temp.find_first_of(']');
  19. vec_val.push_back(temp.substr(index_f + 1, (index_b - index_f - 1)));
  20. }
  21. //the flag of having a result or not
  22. int flag = 0;
  23. for (int i = 0; i < vec_word.size(); i++)
  24. {
  25. if (vec_word[i] == key_word
  26. &&(vec_addr[i].substr(0,2)=="0x"|| vec_addr[i].substr(0, 2) == "0X")
  27. &&(vec_mask[i].substr(0, 2) == "0x" || vec_mask[i].substr(0, 2) == "0X")
  28. &&(vec_val[i].substr(0, 2) == "0x" || vec_val[i].substr(0, 2) == "0X")
  29. && judge_indictionary(vec_addr[i])
  30. && judge_indictionary(vec_mask[i])
  31. && judge_indictionary(vec_val[i]))
  32. {
  33. flag = 1;
  34. cout << vec_addr[i];
  35. cout << " ";
  36. cout << vec_mask[i];
  37. cout << " ";
  38. cout << vec_val[i];
  39. cout << endl;
  40. }
  41. }
  42. //if doesn't find right information
  43. if (flag==0)
  44. cout << "FAIL" << endl;
  45. }

} ```