说明:如下大部分都是测试朋友遇到的笔试题。 html
自问自答,自娱自乐,机会只留给有准备的人java
笔试或者面试的时候,常常被问一些概念,好比同步、异步、阻塞、非阻塞等等,是否是很懵逼?python
http://www.javashuo.com/article/p-qyvabcej-eh.htmlmysql
批量删除/home/test/dist下的全部进程linux
参考答案:ps -ef | grep '/home/test/dist' | awk '{print $2}' | xargs kill -9git
对~/test目录下的全部文件进行排序,且2018开头的,在文件名后加上_bak面试
参考答案:https://gitee.com/UncleYong/exercise/blob/master/modifyFileName.sh算法
二叉树遍历:左序、中序、右序sql
链表操做shell
冒泡排序
二分查找
快速排序
对字符串“2kd4-1124*2|^2sdAmZ%fkMcv”排序,并返回符合要求格式的元组数据。
排序规则:按照ASCII码由大到小排序;
返回数据格式:((最大字符,最小字符),(次大字符,次小字符),,,)
参考答案:http://www.javashuo.com/article/p-dqmjepdq-kx.html
倒置输入的整数
参考答案:http://www.javashuo.com/article/p-pjtxwcgx-kx.html
结构体存储学生学号、姓名、总分,动态内存分配增长信息,而后排序
参考答案:http://www.javashuo.com/article/p-njpjuzwu-kw.html
数组中有一个数字出现的次数超过数组长度的一半
参考答案:http://www.javashuo.com/article/p-dybgnzli-kw.html
将一个字符串中的空格替换成“%20”
参考答案:http://www.javashuo.com/article/p-kujrfznv-kw.html
青蛙跳台阶
参考答案:http://www.javashuo.com/article/p-htvhuhgk-kv.html
找到第一个只出现一次的字符并返回它的位置
参考答案:http://www.javashuo.com/article/p-xdcfyqho-kv.html
python文件操做,http://www.javashuo.com/article/p-exhurbup-ku.html
参考答案:
面向对象小测试
第一部分:http://www.javashuo.com/article/p-kyvgtzxp-kt.html
第二部分:http://www.javashuo.com/article/p-xrroqoqr-kt.html
参考答案:
封装一个函数:生成n个密码,要求包含大小写字母,数字,并对密码进行加盐加密,默认盐值%#$123
参考答案:https://gitee.com/UncleYong/exercise/blob/master/passwords.py
不用中间变量,交换两个变量(同时为数字 or 同时为字符串)的值
参考答案: https://gitee.com/UncleYong/exercise/blob/master/exchageValu.py
运行结果
def fun(arg): print(id(arg)) arg = ['hello'] print(id(arg)) var = ['ok'] print('var: ',id(var)) fun(var) print(var)
http://www.javashuo.com/article/p-hcyxcfgy-ks.html
参考答案: 本身运行,总结规律。
下面代码的做用是移除奇数,运行结果是?为何?
li = [1,1,2,3,4,5,6,7,8,9] for i in li: if i%2!=0: li.remove(i) print(li)
参考答案:[1, 2, 4, 6, 8]
在原代码基础上,如何修改成理想中的答案[2,4,6,8]?(必须保留remove)
方式一(逼格低):
li = [1,1,2,3,4,5,6,7,8,9] li2 = [1,1,2,3,4,5,6,7,8,9] for i in li2: if i%2!=0: li.remove(i) print(li)
方式二(常规思路):
li = [1,1,2,3,4,5,6,7,8,9] li2 = li.copy() for i in li2: if i%2!=0: li.remove(i) print(li)
方案三(高逼格): from:杭州-null-失业老阿姨
li = [1,1,2,3,4,5,6,7,8,9] for i in li[:]: if i%2!=0: li.remove(i) print(li)
其实,更简单的方案是列表生成式
li = list(filter(lambda x:x%2==0, li))
或者
li = [i for i in li if i%2==0]
一行代码实现1-100奇数求和(5种方案)
参考答案:https://gitee.com/UncleYong/exercise/blob/master/sumOfOddNumber.py
下面的输出结果是?
答案是:[6, 6, 6, 6]
详细解释,参考:https://www.cnblogs.com/uncleyong/p/11208987.html
def multipliers(): return [lambda x : i * x for i in range(4)] print([m(2) for m in multipliers()])
等价于
def func(): fun_list = [] for i in range(4): def foo(x): return x*i fun_list.append(foo) print(fun_list) return fun_list res_list = [] for m in func(): res_list.append(m(2)) print(res_list)
递归求1-100质数的和
参考答案:https://gitee.com/UncleYong/exercise/blob/master/RecursiveSumOfPrimeNumber.py
非递归参考答案:
print([x for x in range(2, 101) if all([x%y!=0 for y in range(2, x)])]) print(sum([x for x in range(2, 101) if all([x%y!=0 for y in range(2, x)])]))
【20190715】要求:封装一个方法,实现文件的读、写、改
参考答案:https://gitee.com/UncleYong/exercise/blob/master/filetool.py
【20190712】要求:根据输入的数字n,生成n注大乐透号码,大乐透规则请自行百度
“35选5加12选2”玩法属于双区选号大乐透,玩法简单易懂,彩民们在购买“35选5加12选2”时,能够从01-35共35个号码中,选取5个号码为前区号码,并从01-12共12个号码中选取2个号码为后区号码,组合为一注进行单式投注。
参考答案:https://gitee.com/UncleYong/exercise/blob/master/lottery_ticket.py
【20190711】要求:一行代码,求1-100之间大于10且小于90的数字的平均值
参考答案:https://gitee.com/UncleYong/exercise/blob/master/oneLineCodeSumBetween11And89.py
【20190710】要求:不用sum,最多一个+号,一行代码(不包含导包)实现1到10的累加
备注:只有python实现了一行代码
参考答案(python版):https://gitee.com/UncleYong/exercise/blob/master/MySum.py
参考答案(java版):https://gitee.com/UncleYong/exercise/blob/master/MySum.java
参考答案(shell版):https://gitee.com/UncleYong/exercise/blob/master/MySum.sh
要求:提取出只包含数字及字母,且以字母开头的最长的子字符串,打印出子字符串及其长度,若是有多个,都要打印出来
testStr = '#ab1k23$%&()*+,-./:;<=ab12w4>?666qzcsbj@[4f]^{1aaa12|}'
好比上面字符串提取结果是:
子字符串ab1k23,长度为6
子字符串ab12w4,长度为6
参考答案(正则):https://gitee.com/UncleYong/exercise/blob/master/findMaxSubString.py
参考答案(非正则):https://gitee.com/UncleYong/exercise/blob/master/findMaxSubString2.py
要求:java实现一个类,打印昨天的当前时刻
参考答案:
https://gitee.com/UncleYong/exercise/blob/master/LastDayTime.java
https://gitee.com/UncleYong/exercise/blob/master/TestLastDayTime.java
【20190709】要求:从左到右,每三位进行反转,例如,输入123456789,输出321654987,若是输入1234567890,输出3216549870
参考答案:https://gitee.com/UncleYong/exercise/blob/master/new_str.py
要求:假如你要为一个应用搞限时促销,生成激活码(或者优惠券)请用 Python 如何生成 200 个激活码(或者优惠券)
激活码的格式为asqE-9xRK-lqWU-QkMT
要求1: 使用随机生成时,生成数字几率为1/5,大写字母和小写字母几率各为2/5
要求2: 这200个激活码,他们各不相同
参考答案:https://gitee.com/UncleYong/exercise/blob/master/coupon_gen.py
以mysql为例,单表插入1万条数据,建表的语句:create table test(id int, name varchar(20));
要求:至少两种方案
参考答案一(存储过程,不传参&传参):https://gitee.com/UncleYong/exercise/blob/master/addDatas.sql
参考答案二(py):http://www.javashuo.com/article/p-mwptzawp-cx.html
一个sql题,查询出grade不同的人的全部记录
表stu
参考答案(基于mysql):
方式一:
select * from stu where name in ( select tt.name from ( Select t.code,t.name,t.grade from stu t group by t.code,t.name,t.grade having count(*)=1) tt);
方式二:
select distinct s.* from stu s join( select t.code,t.name,t.grade from stu t group by t.code,t.name,t.grade having count(*)=1) s2 where s.code = s2.code and s.name=s2.name;
方式三:(oracle中下面方式写会报错)
部分图片来源于网络,若有侵权,请联系删除。