随笔分类 - 语言入门
摘要:1.说明下列每对scanf格式串是否等价?如果不等价,请指出它们的差异。 (c) "%f"与"%f "。 在 `scanf` 函数中,`"%f"` 和 `"%f "` 这两种格式的区别在于后面的空格。 1. `scanf("%f", &variable);` 这种情况下,`scanf` 会读取并解析
阅读全文
摘要:(define (list-change total denoms) (define (cons-all num ls) (let ((num-val num)) (cond ((null? ls) nil) (else (cons (cons num (car ls)) (cons-all num
阅读全文
摘要:def mutate_reverse(link): """Mutates the Link so that its elements are reversed. >>> link = Link(1) >>> mutate_reverse(link) >>> link Link(1) >>> link
阅读全文
摘要:(define-macro (switch expr cases) (cons 'cond (map (lambda (case) (cons (eq? (eval expr) (car case)) (cdr case))) cases)) ) 这段代码是一个用于 Scheme 语言的宏定义,可以
阅读全文
摘要:(define-macro (def func args body) `(define ,(cons func args) ,body)) 分析: 定义一个万能的函数定义,那就要模拟函数定义的样子。ok,函数定义是什么样子的呢? eg: (define (filter-lst fn lst) (if
阅读全文
摘要:#lang sicp (define (unique s) (if (null? s) nil (cons (car s) (unique (filter (lambfa (x) (not (eq? x (car s)))) (cdr s))) ) ) ) 这是一个Scheme函数,名为unique
阅读全文
摘要:Write sub-all, which takes a list s, a list of old words, and a list of new words; the last two lists must be the same length. It returns a list with
阅读全文
摘要:def reduce_armor(self, amount): """Reduce armor by AMOUNT, and remove the FireAnt from its place if it has no armor remaining. Make sure to damage eac
阅读全文
摘要:题目: def is_bst(t): """Returns True if the Tree t has the structure of a valid BST. >>> t1 = Tree(6, [Tree(2, [Tree(1), Tree(4)]), Tree(7, [Tree(7), Tr
阅读全文
摘要:重点:: 观察到:在带入函数之后,没有任何返回值,是直接对参数本身进行作用。遇到这种情况就必须在基线条件下多加一个 【return】语句 why? 其实就是人为两种情况,第一种就是t是节点,此时只需要将节点平方就可以了。第二种情况就是有分支,首先呢就将root平方,再将分支进行处理。 1 def l
阅读全文
摘要:#include<iostream> using namespace std; int f(int** r, int ** s){ int temp= **r; int temp2=**s; int * z=*r; *r=*s; *s=z; printf("**r= %d\n",**r); prin
阅读全文
摘要:题目:about generator Write the generator function make_generators_generator, which takes a zero-argument generator function g and returns a generator th
阅读全文
摘要:def close(n, smallest=10, d=10): """ A sequence is near increasing if each element but the last two is smaller than all elements following its subsequ
阅读全文
摘要:Problem 2 题目描述: 代码: 1 def inc_subseqs(s): 2 """Assuming that S is a list, return a nested list of all subsequences 3 of S (a list of lists) for which
阅读全文
摘要:Problem 6 题目描述: 注意事项: 1.不能使用for while循环 2.达到limit时,必须立即返回,不能继续递归 代码: 1.我的代码,很繁琐 1 def shifty_shifts(start, goal, limit): 2 """A diff function for auto
阅读全文
摘要:Q6 题目描述: Write a function has_path that takes in a tree t and a string phrase. It returns True if there is a path that starts from the root where the
阅读全文
摘要:1. >>> odds = [1, 3, 5, 7, 9] >>> [x+1 for x in odds] [2, 4, 6, 8, 10] 2. >>> [x for x in odds if 25 % x == 0] [1, 5] 3 >>> digits = [1, 8, 2, 8] >>>[
阅读全文
摘要:Q1 题目描述: 代码实现: 1 def coords(fn, seq, lower, upper): 2 """ 3 >>> seq = [-4, -2, 0, 1, 3] 4 >>> fn = lambda x: x**2 5 >>> coords(fn, seq, 1, 9) 6 [[-2,
阅读全文
摘要:一:例题 例题1: 题目描述: #递归算法def g(n): """Return the value of G(n), computed recursively. >>> g(1) 1 >>> g(2) 2 >>> g(3) 3 >>> g(4) 10 >>> g(5) 22 >>> from co
阅读全文
摘要:题目描述: 代码: 1 def num_eights(x): 2 """Returns the number of times 8 appears as a digit of x. 3 4 >>> num_eights(3) 5 0 6 >>> num_eights(8) 7 1 8 >>> num
阅读全文

浙公网安备 33010602011771号