本题来自 Project Euler 第17题:https://projecteuler.net/problem=17 ''' Project Euler 17: Number letter counts If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all th…
[Python练习题 005]输入三个整数x,y,z,请把这三个数由小到大输出. ----------------------------------------------------------------------- 这题想想应该比较容易:无非是先获取3个数字,然后比大小,按顺序输出即可.不过在写代码的过程中遇到了个难题:因为担心输入时输入非指定的分隔符,需要指定多个分隔符(英文逗号.中文逗号.空格),但 str.split() 只接受1个分隔符. 上网搜索了下,发现可以用正则表达式解决…
听说做练习是掌握一门编程语言的最佳途径,那就争取先做满100道题吧. ---------------------------------------------------------------------- [Python练习题 001]有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 这题还算比较简单,思路是:先确定百位数.然后是十位数.个位数.1-4 四个数字循环一遍,就都全出来了. res = [] for i in range(1,5): for j in…
Anagramic squares By replacing each of the letters in the word CARE with 1, 2, 9, and 6 respectively, we form a square number: 1296 = 362. What is remarkable is that, by using the same digital substitutions, the anagram, RACE, also forms a square num…
题目 Square digit chains A number chain is created by continuously adding the square of the digits in a number to form a new number until it has been seen before. For example, 44 → 32 → 13 → 10 → 1 → 185 → 89 → 145 → 42 → 20 → 4 → 16 → 37 → 58 → 89 The…
>>> crazystring = ‘dade142.;!0142f[.,]ad’ 只保留数字>>> filter(str.isdigit, crazystring)‘1420142′ 只保留字母>>> filter(str.isalpha, crazystring)‘dadefad’ 只保留字母和数字>>> filter(str.isalnum, crazystring)‘dade1420142fad’ 如果想保留数字0-9和小数点…
<input type="text" maxlength="25" oninput="textlength(this)"> <!--输入的内容--><span class="textNumber">0</span>个字符 <!--字符长度--> <!--调用的jquery方法--> function textlength(res) { var len =…
#Python练习题 001:4个数字求不重复的3位数#方法一import itertoolsres = [][res.append(i[0]*100 + i[1]*10 + i[2]) for i in itertools.permutations(range(1,5),3)]print(res, end = ',') """参考https://www.cnblogs.com/iderek/p/5952126.html""" #方法二for i…
本题来自 Project Euler 第11题:https://projecteuler.net/problem=11 # Project Euler: Problem 10: Largest product in a grid # In the 20×20 grid below, four numbers along a diagonal line have been marked in red. # The product of these numbers is 26 × 63 × 78 ×…
本题来自 Project Euler 第20题:https://projecteuler.net/problem=20 ''' Project Euler: Problem 20: Factorial digit sum n! means n × (n − 1) × ... × 3 × 2 × 1 For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800, and the sum of the digits in the number 10! i…