HDU 1113(map的使用)

谁践踏了优雅 2022-09-20 11:17 225阅读 0赞

题意:给一串字符串字典,再给一串字符串,求字典中是否存在与字符串字符相同的字符串。

  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <algorithm>
  5. using namespace std;
  6. void main()
  7. {
  8. map<string, string> dictionary;
  9. string s, t;
  10. while (cin >> s && s != "XXXXXX")
  11. {
  12. t = s;
  13. sort(s.begin(), s.end());
  14. dictionary[t] = s;
  15. }
  16. while (cin >> s && s != "XXXXXX")
  17. {
  18. int flag = 0;
  19. t = s;
  20. sort(s.begin(), s.end());
  21. map<string, string>::iterator it;
  22. for (it = dictionary.begin(); it != dictionary.end(); ++it)
  23. {
  24. if (it->second == s)
  25. {
  26. cout << it->first << endl;
  27. flag = 1;
  28. }
  29. }
  30. if (!flag)
  31. {
  32. cout << "NOT A VALID WORD" << endl;
  33. }
  34. cout << "******" << endl;
  35. }
  36. }

发表评论

表情:
评论列表 (有 0 条评论,225人围观)

还没有评论,来说两句吧...

相关阅读