poj1035

£神魔★判官ぃ 2022-04-10 08:40 270阅读 0赞

简单题

ContractedBlock.gif ExpandedBlockStart.gif

  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. using namespace std;
  5. const int maxn = 10001;
  6. string dictionary[maxn], checking;
  7. int total;
  8. bool common(string a, string b)
  9. {
  10. int i, different;
  11. string t;
  12. bool first;
  13. if (abs(int(a.length() - b.length())) > 1)
  14. return false;
  15. if (a.length() == b.length())
  16. {
  17. different = 0;
  18. for (i = 0; i < a.length(); i++)
  19. if (a[i] != b[i])
  20. different++;
  21. if (different > 1)
  22. return false;
  23. return true;
  24. }
  25. if (a.length() > b.length())
  26. {
  27. t = a;
  28. a = b;
  29. b = t;
  30. }
  31. first = true;
  32. i = 0;
  33. while (i < a.length())
  34. {
  35. if (a[i] != b[i])
  36. {
  37. if (first)
  38. b.erase(i, 1);
  39. else
  40. return false;
  41. first = false;
  42. }
  43. else
  44. i++;
  45. }
  46. return true;
  47. }
  48. int main()
  49. {
  50. int i;
  51. bool correct;
  52. //freopen("t.txt", "r", stdin);
  53. i = 0;
  54. while (true)
  55. {
  56. getline(cin, dictionary[i]);
  57. if (dictionary[i] == "#")
  58. break;
  59. i++;
  60. }
  61. total = i;
  62. while (true)
  63. {
  64. getline(cin, checking);
  65. if (checking == "#")
  66. break;
  67. cout << checking;
  68. correct = false;
  69. for (i = 0; i < total; i++)
  70. if (checking == dictionary[i])
  71. {
  72. cout << " is correct";
  73. correct = true;
  74. break;
  75. }
  76. if (!correct)
  77. {
  78. cout << ":";
  79. for (i = 0; i < total; i++)
  80. if (common(checking, dictionary[i]))
  81. {
  82. cout << " ";
  83. cout << dictionary[i];
  84. }
  85. }
  86. cout << endl;
  87. }
  88. return 0;
  89. }

发表评论

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

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

相关阅读

    相关 Sicily 1035 DNA matching

    解题思路:        对于每一组数据,把第一个字符串与其以后所有的字符串进行比较(标记第一个字符串),如果互为互补序列,则把该字符串进行标记,并把所求的组数加1,并结束此

    相关 PAT乙级1035

    1035 插入与归并 (25 分) 根据维基百科的定义: 插入排序是迭代算法,逐一获得输入数据,逐步产生有序的输出序列。每步迭代中,算法从输入序列中取出一元素,将之插入有序