2020年6月2日
摘要: 列表生成式即List Comprehensions,是Python内置的非常简单却强大的可以用来创建list的生成式。 举个例子,要生成list [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]可以用list(range(1, 11)): >>> list(range(1, 11)) 阅读全文
posted @ 2020-06-02 21:26 满船清梦压星河1024 阅读(237) 评论(0) 推荐(0)
摘要: 如果要对list实现类似Java那样的下标循环怎么办?Python内置的enumerate函数可以把一个list变成索引-元素对,这样就可以在for循环中同时迭代索引和元素本身: >>> for i, value in enumerate(['A', 'B', 'C']): ... print(i, 阅读全文
posted @ 2020-06-02 20:55 满船清梦压星河1024 阅读(138) 评论(0) 推荐(0)
  2020年5月30日
摘要: 一、dict函数 如果用dict实现,只需要一个“名字”-“成绩”的对照表,直接根据名字查找成绩,无论这个表有多大,查找速度都不会变慢。用Python写一个dict如下: >>> d = {'Michael': 95, 'Bob': 75, 'Tracy': 85} >>> d['Michael'] 阅读全文
posted @ 2020-05-30 22:52 满船清梦压星河1024 阅读(202) 评论(0) 推荐(0)
摘要: Python的循环有两种,一种是for...in循环,依次把list或tuple中的每个元素迭代出来,看例子: names = ['Michael', 'Bob', 'Tracy'] for name in names: print(name) 执行这段代码,会依次打印names的每一个元素: Mi 阅读全文
posted @ 2020-05-30 22:31 满船清梦压星河1024 阅读(228) 评论(0) 推荐(0)
  2020年5月29日
摘要: 一、list函数 list是一个可变的有序表,所以,可以往list中追加元素到末尾: >>> classmates.append('Adam')>>> classmates['Michael', 'Bob', 'Tracy', 'Adam']也可以把元素插入到指定的位置,比如索引号为1的位置: >> 阅读全文
posted @ 2020-05-29 12:15 满船清梦压星河1024 阅读(393) 评论(0) 推荐(0)
  2020年5月28日
摘要: 1.用链表加循环的方式 n=123 f=456.456 s1='Hello,world' s2='Hello,\'lihua\'' s3=r'hello,"Bart"' s4=r'''hello Lisa!''' L=[n,f,s1,s2,s3,s4] for M in L: print(M) 2. 阅读全文
posted @ 2020-05-28 20:38 满船清梦压星河1024 阅读(7555) 评论(0) 推荐(1)
  2020年5月11日
摘要: 问题: a,b之间(不含a,b)所有素数的和。有多组测试样例,输入直到文件末尾,每组样例占一行, a b (0<=a,b<=65536)。 对每组样例输出占一行,输出内容为a,b之间(不含a,b)所有素数的和。 完整代码:注意一定不能变,所有的细节都要一样,不然过不去OJ #include <std 阅读全文
posted @ 2020-05-11 18:06 满船清梦压星河1024 阅读(575) 评论(0) 推荐(0)
  2020年5月10日
摘要: #include <stdio.h> void main() { int t,n,m; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); int i,s; int a[10000][2]={0}; for(i=0;i<n;i++) { scanf(" 阅读全文
posted @ 2020-05-10 19:11 满船清梦压星河1024 阅读(359) 评论(0) 推荐(0)
  2020年5月9日
摘要: 完整代码: #include<stdio.h> #include<string.h> void main(){ int n; scanf("%d",&n); int i,j,k; printf(" "); for(i=0;i<n;i++){ printf("-"); } printf(" \n"); 阅读全文
posted @ 2020-05-09 18:36 满船清梦压星河1024 阅读(427) 评论(0) 推荐(0)
摘要: Input: 输入有包括多组数据。每组数据包括一行字符串。 Output: 输出加密后的字符串。 Sample Input: I Love You Sample Output: I evoL uoY 解析:利用数组计数,把非空格的字符记下来,空格代表一个间断,经过空格后计数要重新开始 完整代码: # 阅读全文
posted @ 2020-05-09 12:41 满船清梦压星河1024 阅读(606) 评论(0) 推荐(0)