方法一:for循环遍历 counter=0 for i in range(1,5): for j in range(1,5): for k in range(1,5): if i !=j and j !=k and k !=i: print("{}{}{}".format(i,j,k),end=" ") counter +=1 print("") print("共{}种组合".format(counter)) 方法二:用ite…
Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", the answer is "abc", which the length is 3. Given "bbbbb", the answer is "b", with the length of 1.…
有四个数字能组成多少个互不相同的三位数? num = 0 for i in range(1, 5): for j in range(1, 5): for k in range(1, 5): if i != j and i != k and j != k: num += 1 print(num) 可以组成24个互不相同的三位数.…
JAVA经典算法40例 [程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21.... public class exp2{ public static void main(String args[]){ int i=0; for(i=1;i<=20;i++) System.out.println(f(i))…
#有五个数字:1.2.3.4.5,能组成多少个互不相同且无重复数字的四位数?各是多少? e =[] for a in range(1,6): for b in range(1,6): for c in range(1,6): for d in range(1,6): if a!=b and a!=c and a!=d and b!=c and b!=d and c!=d: e.append(str(a)+str(b)+str(c)+str(d)) print("组成数量:%d" %le…
[程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21.... public class exp2{ public static void main(String args[]){ int i=0; for(i=1;i<=20;i++) System.out.println(f(i)); } publ…
1.排列计算 /*[程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21.... */ package cn.com.flywater.FiftyAlgorthm; public class FirstRabbit { public static final int MONTH = 15; public static voi…
JAVA经典算法40题 [程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 1.程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21.... public class exp2{ public static void main(String args[]){ int i=0; for(i=1;i<=20;i++) System.out.println(f(i)); }…
50道JAVA基础编程练习题 [程序1] 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21.... public class Prog1{ public static void main(String[] args){ int n = 10; System.out.println("第"+n+"个月兔子总数为&qu…