Python写算法基础
输入:
N,C=map(int,input().split())
1.input()读取输入的字符串
2.split()按照空格分成列表,也可以按照其他的符号划分,.split(",")
3.map(),将输入内容的数据类型转换为int
4.N,C=赋值
以上读入适用于同一行,多行数据应循环读入。
x=[]
idx=1
line = input().strip()
x.append([int(char) for char in line])
n = len(line)
while True:if idx==n:breakline = input().strip()idx+=1x.append([int(char) for char in line])
其中:
line = input().strip()
.strip()用于删除字符串首尾的特定字符,默认空白
s = "***hello***"
print(s.strip('*')) # 输出: 'hello'
参考:
P1320 压缩技术(续集版) - 洛谷
计算符号:
//取整运算
/除法,得到小数
%取模运算
print(359%100) 59
print(359/100) 3.59
print(359//100) 3
循环:
range(10000,30000) 起始值包含,结束值不包含
内置函数:
数字转字符串,并统计某字符的个数 temp=str(i) num+=temp.count('2')