(1)找出字符串s=”aaabbbccceeefff111144444″中,字符出现次数最多的字符
考虑去重,首先将字符串进行过滤去重,这样在根据这些字符进行循环查询时,将会减少循环次数,提升效率。但是本人写的代码较为臃肿,有更好的希望留言评论
利用set自身的去重功能
param str1: 对传进来的字符串过滤
return: 返回一个不含重复字符的list
对已经去重的list进行遍历,因已去重
从而减少循环次数,提高检索效率
不考虑去重
(2)有四个数字:1、2、3、4,能组成多少个互不相同且无重复数字的三位数?各是多少?
按题意直接写出来
其实python自带排列组合模块,可以直接调用。
也知道这个写法,只是函数记不住,还是百度一下才能写出来。如果这是面试题,能写出后一种当然好,不能的话还是老老实实的按照上面的思路来吧。
(3)企业发放的奖金根据利润(I)的多少来提成:
低于或等于10万元时,奖金可提10%;
利润高于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可提成7.5%;
20万到40万之间时,高于20万元的部分,可提成5%;
40万到60万之间时高于40万元的部分,可提成3%;
60万到100万之间时,高于60万元的部分,可提成1.5%;
高于100万元时,超过100万元的部分按1%提成。
从键盘输入当月利润I,求应发放奖金总数?
'''
def tm002():
'''
程序分析:请利用数轴来分界,定位。
【思路】:这种处理数轴问题的写法,值得参考。比elif的写法,简洁方便的多。
(4)一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
【思路】:网站上是求了一下方程,没细看。
python又不是没有开方函数,直接按字面意思解了。
(5)输入某年某月某日,判断这一天是这一年的第几天?
【思路】:知道python有时间元组这一概念,这道题完全不需要计算。
时间元组包含九个属性
tm_year 年
tm_mon 月(1~12)
tm_mday 日(1~31)
tm_hour 时(0~23)
tm_min 分(0~59)
tm_sec 秒(0~61, 60或61是闰秒)
tm_wday 星期(0~6, 0是周一)
tm_yday 第几天(1~366, 366是儒略历)
tm_isdst 夏令时(平时用不到)