当前位置:   article > 正文

微软笔试题(苏州)_苏州微软笔试试题

苏州微软笔试试题

题目是  小明迷路了,求出他的方位,具体的题目没了,所以没有弄过来,希望大家海涵或者提供一下


  1. #include <iostream>
  2. #include <utility>
  3. #include <fstream>
  4. using namespace std;
  5. int N;
  6. int M;
  7. char ** allmap;
  8. char ** side;
  9. int const side_length = 3;
  10. const pair<int,int> error = make_pair(-1,-1);
  11. bool northcheckplace(int x,int y);
  12. void getdata();
  13. void findplace();
  14. bool eastcheckplace(int x,int y);
  15. bool sourthcheckplace(int x,int y);
  16. bool westhcheckplace(int x,int y);
  17. void readdata();
  18. int main()
  19. {
  20. getdata();
  21. //readdata();
  22. findplace();
  23. system("pause");
  24. return 0;
  25. }
  26. void getdata()
  27. {
  28. cin>>N;
  29. cin>>M;
  30. allmap = new char*[N];
  31. for(int i=0;i<N;i++)
  32. {
  33. allmap[i] = new char[M];
  34. for(int j=0;j<M;j++)
  35. {
  36. cin>>allmap[i][j];
  37. }
  38. }
  39. side = new char*[side_length];
  40. for(int i=0;i<side_length;i++)
  41. {
  42. side[i] = new char[side_length];
  43. for(int j=0;j<side_length;j++)
  44. {
  45. cin>>side[i][j];
  46. }
  47. }
  48. }
  49. void findplace()
  50. {
  51. pair<int,int> result;
  52. result = error;
  53. for(int i=0;i <= N-side_length;i++)
  54. for(int j=0;j <= M-side_length;j++)
  55. {
  56. if( northcheckplace(i,j) == true )
  57. cout<<i+2<<" "<<j+2<<endl;
  58. else if( eastcheckplace(i,j) == true )
  59. {
  60. cout<<i+2<<" "<<j+2<<endl;
  61. }
  62. else if( sourthcheckplace(i,j) == true )
  63. {
  64. cout<<i+2<<" "<<j+2<<endl;
  65. }
  66. else if( westhcheckplace(i,j) == true )
  67. {
  68. cout<<i+2<<" "<<j+2<<endl;
  69. }
  70. }
  71. }
  72. bool northcheckplace(int x,int y)
  73. {
  74. for(int i=0;i<side_length;i++)
  75. for(int j=0;j<side_length;j++)
  76. {
  77. if(allmap[x+i][y+j] != side[i][j])
  78. return false;
  79. }
  80. return true;
  81. }
  82. bool eastcheckplace(int x,int y)
  83. {
  84. for(int i=0;i<side_length;i++)
  85. for(int j=0;j<side_length;j++)
  86. {
  87. if(allmap[x+i][y+j] != side[side_length-j-1][i])
  88. return false;
  89. }
  90. return true;
  91. }
  92. bool sourthcheckplace(int x,int y)
  93. {
  94. for(int i=0;i <side_length ;i++)
  95. for(int j=0;j <side_length;j++)
  96. {
  97. if(allmap[x+i][y+j] != side[side_length-1-i][side_length-1-j])
  98. return false;
  99. }
  100. return true;
  101. }
  102. bool westhcheckplace(int x,int y)
  103. {
  104. for(int i=0;i<side_length;i++)
  105. for(int j=0;j<side_length;j++)
  106. {
  107. if(allmap[x+i][y+j] != side[j][side_length-1-i])
  108. return false;
  109. }
  110. return true;
  111. }
  112. void readdata()
  113. {
  114. ifstream reader;
  115. reader.open("data.txt");
  116. reader>>N;
  117. reader>>M;
  118. allmap = new char*[N];
  119. for(int i=0;i<N;i++)
  120. {
  121. allmap[i] = new char[M];
  122. for(int j=0;j<M;j++)
  123. {
  124. reader>>allmap[i][j];
  125. }
  126. }
  127. side = new char*[side_length];
  128. for(int i=0;i<side_length;i++)
  129. {
  130. side[i] = new char[side_length];
  131. for(int j=0;j<side_length;j++)
  132. {
  133. reader>>side[i][j];
  134. }
  135. }
  136. reader.close();
  137. }


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/555393
推荐阅读
相关标签
  

闽ICP备14008679号