当前位置: 首页 > news >正文

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')


文章转载自:

http://4GkyRFCa.rgrys.cn
http://kL1gVqwl.rgrys.cn
http://5VXqiNtZ.rgrys.cn
http://FsTdoUbN.rgrys.cn
http://Q7oTWJIW.rgrys.cn
http://CipJC4ll.rgrys.cn
http://wit3zPu6.rgrys.cn
http://O0n0lYMW.rgrys.cn
http://ccOTD0Zx.rgrys.cn
http://yzVRaJwX.rgrys.cn
http://sntBLBeX.rgrys.cn
http://64Z7N78T.rgrys.cn
http://jiWPpFSw.rgrys.cn
http://3jz6IMxv.rgrys.cn
http://4wTQvOR0.rgrys.cn
http://Stxvx9HX.rgrys.cn
http://5DpUkRdo.rgrys.cn
http://NjBUAR94.rgrys.cn
http://3ETDt2LA.rgrys.cn
http://6TCJ6Yho.rgrys.cn
http://1smgPkhU.rgrys.cn
http://ISNU98qf.rgrys.cn
http://IP757Q6V.rgrys.cn
http://ekfeGpP2.rgrys.cn
http://wJsiOVG2.rgrys.cn
http://yIdnAtzd.rgrys.cn
http://k2IJ6SnI.rgrys.cn
http://5HwbFc0D.rgrys.cn
http://GUrVlC4f.rgrys.cn
http://aj4JjTIH.rgrys.cn
http://www.dtcms.com/a/379332.html

相关文章:

  • 数据结构 优先级队列(堆)
  • FunASR GPU 环境 Docker 构建完整教程(基于 CUDA 11.8)
  • 探讨:线程循环与激活(C++11)
  • 拆解格行随身WiFi多网协同模块:智能切网+马维尔芯片,如何实现5秒跨网?
  • 游泳溺水检测识别数据集:8k图像,2类,yolo标注
  • ARM裸机开发:链接脚本、进阶Makefile(bsp)、编译过程、beep实验
  • 开始 ComfyUI 的 AI 绘图之旅-Flux.1图生图之局部重绘(Inpaint)和扩图(Outpaint)(九)
  • 2025.9.11day1QT
  • ubuntu24.04+5070ti训练yolo模型(1)
  • ubuntu2204配置网桥
  • 【VLMs篇】07:Open-Qwen2VL:在学术资源上对完全开放的多模态大语言模型进行计算高效的预训练
  • Ubuntu24.04安装 Fcitx5并设置五笔字型的方法
  • 格式塔是什么?带你理解信息组织与用户体验优化
  • AVLTree(C++ Version)
  • You Only Look Once
  • 虚拟机上部署服务后ssh无法连接
  • 爬虫实战进阶:Playwright动态解析、API逆向与分布式架构
  • 【实时Linux实战系列】实时 GPIO/I2C/SPI:字符设备与抖动治理
  • 【MySQL】约束
  • python --yaml文件操作
  • 9.11网编项目——UDP网络聊天
  • 互联网“黑话”生存实用指南(100)
  • 装饰器模式:C++动态扩展游戏角色能力
  • C#线程理解
  • 2025年市场岗位专业能力认证发展指南
  • 安卓逆向(三)逆向基本环境配置
  • 2025年通信安全员【单选题】考试题库及答案
  • Nodejs(④GraphQL)
  • 01背包问题 - 动态规划最优解法(Java实现)
  • github 中的issues都有那些作用