zoukankan      html  css  js  c++  java
  • day18

    day18
    1.编程求 s=1!+2!+3!+…..+n!
    >>> n = 5
    >>> s = 0
    >>> t = 1
    >>> for i in range(1,n+1):
    ... t *= i
    ... s ++ t
     
    2.钞票换硬币 把一元钞票换成一分、二分、五分硬币(每种至少一枚),有多种换法,分 别有哪些?
    >>> result = []
    >>> count = 0
    >>> for i in range(int(remain/1)):
    ... for j in range(int(remain/2)):
    ... for k in range(int(remain/5)):
    ... if(i + 2*j +k*5) == 92:
    ... count += 1
    ... result.append((i,j,k))
     
    3.自己实现在一句话中查找某个单词的算法,存在返回索引号,否则返回 False
    s = "you are a beautiful girl good"
    def find_word(s, word):
    word_len = len(word)
    for i in range(len(s)):
    if s[i:i+word_len] == word:
    return i
    return False
     
    4.读入一个十进制整数,实现十进制转二进制算法将其转成二进制数 要求:不能使用现成进制转换函数,自己写代码实现
    def dec_to_bin(num):
    if isinstance(num, int):
    result = []
    while True:
    temp = num % 2
    num = num // 2
    result.append(str(temp))
    if num == 0:
    break
    return result[::-1]

  • 相关阅读:
    c++笔记3
    c++笔记2
    c++笔记1
    零点追踪(零点及量程补偿)
    优秀软件:
    Hart协议
    RL_RTX函数
    keil-rtx
    电源模块选型
    RTX51 Tiny
  • 原文地址:https://www.cnblogs.com/jueshilaozhongyi/p/12089490.html
Copyright © 2011-2022 走看看