Guest User

Untitled

a guest
Mar 22nd, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. 编程题B:使用熟悉的语言实现, 请直接在输入框中撰写答案,【不要】复制黏贴
  2.  
  3. 教育局拿到了两个学校的学生高考总分列表,并分别按总分从高到低排好了序。请写一段代码,把两个列表按总分从高到低合并后输出;请勿使用语言自带的相关函数。
  4. ```
  5. <?php
  6. /**
  7. * 'school'=>,//
  8. * 'id'=>,//xue'hao学号
  9. * 'name'=>,//xing'm姓名
  10. * 'store'=>,//fen'shu分数
  11. */
  12. function merge_ranking($one_school_ranking, $other_school_ranking)
  13. {
  14. $ret = [];
  15. $one_school_student = array_shift($one_school_ranking);
  16. $other_school_student = array_shift($other_school_ranking);
  17. while (true) {
  18.  
  19. if (is_null($one_school_student)) {
  20. $ret = append_arr($ret, $other_school_ranking);
  21. break;
  22. } elseif (is_null($other_school_student)) {
  23. $ret = append_arr($ret, $one_school_ranking);
  24. break;
  25. } elseif ($one_school_student['store'] > $other_school_student['store']) {
  26. $ret[] = $one_school_student;
  27. $one_school_student = array_shift($one_school_ranking);
  28. } else {
  29. $ret[] = $other_school_student;
  30. $other_school_student = array_shift($other_school_ranking);
  31. }
  32.  
  33. }
  34. return $ret;
  35. }
  36.  
  37. /***
  38. *jiang将 bshu'zu数组 zhui'jia追加dao追加到ashu'zu数组 d的 hou'm后面
  39. */
  40. function append_arr($a, $b)
  41. {
  42. foreach ($b as $o) {
  43. $a[] = $o;
  44. }
  45. return $a;
  46. }
  47.  
  48. var_dump(merge_ranking([
  49. [
  50. 'school' => 'yizhong',
  51. 'id' => 1,
  52. 'store' => 98
  53. ],
  54. [
  55. 'school' => 'yizhong',
  56. 'id' => 2,
  57. 'store' => 95
  58. ],
  59. [
  60. 'school' => 'yizhong',
  61. 'id' => 3,
  62. 'store' => 93
  63. ],
  64. ], [
  65. [
  66. 'school' => 'erzhong',
  67. 'id' => 1,
  68. 'store' => 98
  69. ],
  70. [
  71. 'school' => 'erzhong',
  72. 'id' => 2,
  73. 'store' => 96
  74. ],
  75. [
  76. 'school' => 'erzhong',
  77. 'id' => 3,
  78. 'store' => 93
  79. ],
  80. ]));
  81. ```
  82.  
  83. 编程题A:选做其中【一个】题目,使用熟悉的语言实现, 请直接在输入框中撰写答案,【不要】复制黏贴
  84.  
  85. (1) 生活中我们一般用10进制数,但我们也使用其他的进制,例如时/分/秒分别用了24/60/60进制。在某个特殊场景下,我们需要使用a,b,c,...,j,k,l,m表示0~12,用于记录13进制数字,但却不便于阅读和比较,现在请你写一个函数,把输入的13进制数字转化成10进制数字,例如,输入 "bbb" ,应该得出10进制数 183 。
  86.  
  87. (2) 从随机数发生器中连续取出1000个数字组成的序列,求其中最长的递增序列的长度;例如取出 [1,9,5,6,8,2,4],最长的递增序列是[5,6,8],长度为3。
  88.  
  89. (3) 实现一个函数 add ,输入参数是两个用字符串表达的整数(长度不超过100位),计算并返回两个数字的和(请勿使用语言自带库函数)。例如: add("123", "45") 返回结果应当是 "168"。
  90.  
  91. 选做第一道
  92. ```
  93. <?php
  94. function contrast_from_13_to_10($num_13){
  95. $contrast = [
  96. 'a'=>0,
  97. 'b'=>1,
  98. 'c'=>2,
  99. 'd'=>3,
  100. 'e'=>4,
  101. 'f'=>5,
  102. 'g'=>6,
  103. 'h'=>7,
  104. 'i'=>8,
  105. 'j'=>9,
  106. 'k'=>10,
  107. 'l'=>11,
  108. 'm'=>12
  109. ];
  110. $len = strlen($num_13);
  111. $ret = 0;
  112. for($i=0;$i<$len;$i++){
  113. $one_digit = $contrast[substr($num_13,$len-1-$i,1)];
  114. $ret += $one_digit*pow(13,$i);
  115. }
  116. return $ret;
  117. }
  118.  
  119. echo contrast_from_13_to_10('bbb');
  120. ```
  121.  
  122. 数据库(SQL):已知数据表 t 包含字段 line(线路号), station(站点名称), seq(站点在该线路的序号), 例如
  123.  
  124. line station seq
  125. 1 莘庄 1
  126. 1 人民广场 13
  127. 5 莘庄 1
  128. 8 人民广场 15
  129. … …
  130.  
  131. (1) 求经过最多站点的线路
  132. ```
  133. SELECT
  134. *
  135. FROM
  136. (
  137. SELECT
  138. station,
  139. count(*) AS num
  140. FROM
  141. t
  142. GROUP BY
  143. station
  144. ) AS station_count
  145. ORDER BY
  146. num DESC
  147. LIMIT 1;
  148. ```
  149. (2) 如何判断A、B两个站点能否直达?
  150. ```
  151.  
  152. select * from t where station="莘庄" and line in (select line from t where station="人民广场");
  153. ```
  154. (3) (选做) 请制造一个死锁
Add Comment
Please, Sign In to add comment