Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 编程题B:使用熟悉的语言实现, 请直接在输入框中撰写答案,【不要】复制黏贴
- 教育局拿到了两个学校的学生高考总分列表,并分别按总分从高到低排好了序。请写一段代码,把两个列表按总分从高到低合并后输出;请勿使用语言自带的相关函数。
- ```
- <?php
- /**
- * 'school'=>,//
- * 'id'=>,//xue'hao学号
- * 'name'=>,//xing'm姓名
- * 'store'=>,//fen'shu分数
- */
- function merge_ranking($one_school_ranking, $other_school_ranking)
- {
- $ret = [];
- $one_school_student = array_shift($one_school_ranking);
- $other_school_student = array_shift($other_school_ranking);
- while (true) {
- if (is_null($one_school_student)) {
- $ret = append_arr($ret, $other_school_ranking);
- break;
- } elseif (is_null($other_school_student)) {
- $ret = append_arr($ret, $one_school_ranking);
- break;
- } elseif ($one_school_student['store'] > $other_school_student['store']) {
- $ret[] = $one_school_student;
- $one_school_student = array_shift($one_school_ranking);
- } else {
- $ret[] = $other_school_student;
- $other_school_student = array_shift($other_school_ranking);
- }
- }
- return $ret;
- }
- /***
- *jiang将 bshu'zu数组 zhui'jia追加dao追加到ashu'zu数组 d的 hou'm后面
- */
- function append_arr($a, $b)
- {
- foreach ($b as $o) {
- $a[] = $o;
- }
- return $a;
- }
- var_dump(merge_ranking([
- [
- 'school' => 'yizhong',
- 'id' => 1,
- 'store' => 98
- ],
- [
- 'school' => 'yizhong',
- 'id' => 2,
- 'store' => 95
- ],
- [
- 'school' => 'yizhong',
- 'id' => 3,
- 'store' => 93
- ],
- ], [
- [
- 'school' => 'erzhong',
- 'id' => 1,
- 'store' => 98
- ],
- [
- 'school' => 'erzhong',
- 'id' => 2,
- 'store' => 96
- ],
- [
- 'school' => 'erzhong',
- 'id' => 3,
- 'store' => 93
- ],
- ]));
- ```
- 编程题A:选做其中【一个】题目,使用熟悉的语言实现, 请直接在输入框中撰写答案,【不要】复制黏贴
- (1) 生活中我们一般用10进制数,但我们也使用其他的进制,例如时/分/秒分别用了24/60/60进制。在某个特殊场景下,我们需要使用a,b,c,...,j,k,l,m表示0~12,用于记录13进制数字,但却不便于阅读和比较,现在请你写一个函数,把输入的13进制数字转化成10进制数字,例如,输入 "bbb" ,应该得出10进制数 183 。
- (2) 从随机数发生器中连续取出1000个数字组成的序列,求其中最长的递增序列的长度;例如取出 [1,9,5,6,8,2,4],最长的递增序列是[5,6,8],长度为3。
- (3) 实现一个函数 add ,输入参数是两个用字符串表达的整数(长度不超过100位),计算并返回两个数字的和(请勿使用语言自带库函数)。例如: add("123", "45") 返回结果应当是 "168"。
- 选做第一道
- ```
- <?php
- function contrast_from_13_to_10($num_13){
- $contrast = [
- 'a'=>0,
- 'b'=>1,
- 'c'=>2,
- 'd'=>3,
- 'e'=>4,
- 'f'=>5,
- 'g'=>6,
- 'h'=>7,
- 'i'=>8,
- 'j'=>9,
- 'k'=>10,
- 'l'=>11,
- 'm'=>12
- ];
- $len = strlen($num_13);
- $ret = 0;
- for($i=0;$i<$len;$i++){
- $one_digit = $contrast[substr($num_13,$len-1-$i,1)];
- $ret += $one_digit*pow(13,$i);
- }
- return $ret;
- }
- echo contrast_from_13_to_10('bbb');
- ```
- 数据库(SQL):已知数据表 t 包含字段 line(线路号), station(站点名称), seq(站点在该线路的序号), 例如
- line station seq
- 1 莘庄 1
- 1 人民广场 13
- 5 莘庄 1
- 8 人民广场 15
- … …
- (1) 求经过最多站点的线路
- ```
- SELECT
- *
- FROM
- (
- SELECT
- station,
- count(*) AS num
- FROM
- t
- GROUP BY
- station
- ) AS station_count
- ORDER BY
- num DESC
- LIMIT 1;
- ```
- (2) 如何判断A、B两个站点能否直达?
- ```
- select * from t where station="莘庄" and line in (select line from t where station="人民广场");
- ```
- (3) (选做) 请制造一个死锁
Add Comment
Please, Sign In to add comment