山东理工大学SDUT - ACM OJ 题: Python代码 及分析
Python基础语法学习完成,先刷基础题100道巩固 ,附 题目、代码、知识分析
题目:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1000.html 代码:
s = input().split();
print((int)(s[0])+(int)(s[1])) 知识分析:
1、python输入 input()
2、split() 是分割字符串操作
3、python可以用str[0] 取字符串下标为0的字符
1000、A+B Problem
题目:http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1010.html 代码:
while True:
s=input().split()
print((int)(s[0])+(int)(s[1])) 分析知识:
1、Python的布尔类型有 True False 记住是大写
2、while True : 后面冒号必须有 括号不一定需要有,规范是没有 和java不同
1010、A+B for Input-Output Practice (I)
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1011.html 代码:
num = (int)(input())
for i in range(1,num+1):
s = input().split()
print((int)(s[0])+(int)(s[1])) 知识分析:
1、for 循环使用 结构 for i in range(1,num+1)
则 i 的取值范围是 1 到 num
1011、A+B for Input-Output Practice (II)
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1012.html 代码:
while True:
s = input().split()
if (int)(s[0])==0 and (int)(s[1])==0:
break
print((int)(s[0])+(int)(s[1])) 知识分析:
1、python的且运算是and 或运算是or
1012、A+B for Input-Output Practice (III)
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1013.html 代码:
while True:
s=input().split()
if s==['']:
break
sum = 0;
for i in range(1,len(s)):
sum=sum+(int)(s[i])
print(sum)
1013、A+B for Input-Output Practice (IV)
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1014.html 代码:
s = input()
for i in range(0 , int(s)):
s=input().split()
sum = 0;
for i in range(1,len(s)):
sum=sum+(int)(s[i])
print(sum)
1014、A+B for Input-Output Practice (V)
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1015.html 代码:
while True:
s=input().split()
sum=0
for i in range(1,len(s)):
sum+=(int)(s[i])
print(sum) 知识分析:
无
1015、A+B for Input-Output Practice (VI)
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1016.html 代码:
while True:
s=input().split()
print((int)(s[0])+(int)(s[1]))
print()
1016、A+B for Input-Output Practice (VII)
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1017.html 代码:
s=input()
for i in range(0,(int)(s)):
ss = input().split()
sum = 0;
for j in range(1,len(ss)):
sum+=(int)(ss[j])
print(sum)
print()
1017、A+B for Input-Output Practice
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1123.html 代码:
num=(int)(input())
if num==0:
print(1)
else:
sum = 1;
i=0
for i in range(1,num+1):
sum *= i print(sum) 知识分析:
1、if else 里面都需要有:
1123、求阶乘(循环结构)
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1201.html 代码:
s=input().split(" ")
#将三个字符串加入列表
list = []
list.append(s[0])
list.append(s[1])
list.append(s[2])
list.sort() for i in range(len(list)):
print(list[i],end='')
print(" ",end='') 知识分析:
1、list添加元素方法 append
2、list排序方法 sort()
3、输出不换行 加 ,end=''
1201、字符串排序
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1249.html 代码:
while True:
s = input()
print(s.title()) 知识分析:
1、input()输入后即 字符串
2、s.title() 内置方法 将每个单词的第一个字母转为大写 其余小写 其他方法如下: str = "www.runoob.com"
print(str.upper()) # 把所有字符中的小写字母转换成大写字母
print(str.lower()) # 把所有字符中的大写字母转换成小写字母
print(str.capitalize()) # 把第一个字母转化为大写字母,其余小写
print(str.title()) # 把每个单词的第一个字母转化为大写,其余小写
执行以上代码输出结果为:
WWW.RUNOOB.COM
www.runoob.com
Www.runoob.com
Www.Runoob.Com
1249、首字母变大写
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/1442.html 代码:
num=(int)(input())
for i in range(0,num):
s = input().split(" ")
# 用空格分割 是字符串 转成整形 存到列表中
list = []
list.append((int)(s[0]))
list.append((int)(s[1]))
list.append((int)(s[2]))
ave = (list[0]+list[1]+list[2])/3 #算平均数
isLarge = 0 # 3个数中 大于平均数的个数
for j in list:
if j > ave:
isLarge+=1 if isLarge>1:
print("Yes")
else:
print("No") 知识分析:
1、range(0,num) 的取值范围是0到num-1
2、 s = input().split(" ") 获取的是用空格分割的字符串 并存入到列表中
比如输入 : 1 2 3
s 的值就是 : ['', '', '']
1442、优越数
题目:
http://acm.sdut.edu.cn/onlinejudge2/index.php/Home/Index/problemdetail/pid/2247.html 代码:
s=input().split(" ")
print(s[0].count(s[1])) 知识分析:
1、str.count(s) 返回s在str中出现的次数
2247、统计次数问题
山东理工大学SDUT - ACM OJ 题: Python代码 及分析的更多相关文章
- [python]Python代码安全分析工具(Bandit)
简介: Bandit是一款Python源码分析框架,可用于Python代码的安全性分析.Bandit使用标准库中的ast模块,将Python源码解析成Python语法节点构成的树.Bandit允许用户 ...
- python 代码性能分析 库
问题描述 1.Python开发的程序在使用过程中很慢,想确定下是哪段代码比较慢: 2.Python开发的程序在使用过程中占用内存很大,想确定下是哪段代码引起的: 解决方案 使用profile分析分析c ...
- 朴素贝叶斯算法简介及python代码实现分析
概念: 贝叶斯定理:贝叶斯理论是以18世纪的一位神学家托马斯.贝叶斯(Thomas Bayes)命名.通常,事件A在事件B(发生)的条件下的概率,与事件B在事件A(发生)的条件下的概率是不一样的:然而 ...
- 使用 profile 进行python代码性能分析
定位程序性能瓶颈 对代码优化的前提是需要了解性能瓶颈在什么地方,程序运行的主要时间是消耗在哪里,对于比较复杂的代码可以借助一些工具来定位,python 内置了丰富的性能分析工具,如 profile,c ...
- ACM 做题过程中的一些小技巧。
ACM做题过程中的一些小技巧. 1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 2.有时候int型不够用,可以用long l ...
- 各大ACM OJ网址
做快乐的程序员 以你的条件,你不必追求优秀,但你可以做到良好. 各大OJ网址 ACM OJ Collection(排名不分先后): 中国:(China) 华东地区: 浙江: 杭州电子科技大学(HDU) ...
- 用PHP语言刷OJ题
平常在学校都是用C,C++,Java来刷OJ题,把AC的题用不同的语言再AC一次,基本相当于翻译而已.看到学校的OJ支持提交PHP代码,于是尝试了一下. 首先,得会使用PHP,但是你如果在看这篇博客, ...
- 一起来写2048(160行python代码)
前言: Life is short ,you need python. --Bruce Eckel 我与2048的缘,不是缘于一个玩家,而是一次,一次,重新的ACM比赛.四月份校赛初赛,第一次碰到20 ...
- 一起写2048(160行python代码)
前言: Life is short ,you need python. --Bruce Eckel 我与2048的缘,不是缘于一个玩家.而是一次,一次,重新的ACM比赛.四月份校赛初赛,第一次碰到20 ...
随机推荐
- PHP环境搭建时缺少php7apache2_4.dll怎么办
PHP环境搭建时缺少php7apache2_4.dll怎么办 下载的文件有问题! 1.在PHP官网点击Download下载时不管选择哪个版本的都有两个类型 如果需要 php7apache2_4.dl ...
- Ubantu linux中使用PyCharm之---破解PyCharm,实现永久免费试用
打开 http://idea.lanyus.com/ 这个网址,可以直接复制到浏览器打开 获取注册码 K71U8DBPNE-eyJsaWNlbnNlSWQiOiJLNzFVOERCUE5FIiwibG ...
- 什么是SQL
SQL是用于访问和处理数据库的标准的计算机语言 SQL是 访问 .处理数据库中的数据 ,这类数据库 包括Oracle, Sybase, SQL Server, DB2,Accesss等等 类型的数据库 ...
- css笔记详解(1)
css讲解 版权声明 本文原创作者:雨点的名字 作者博客地址:https://home.cnblogs.com/u/qdhxhz/ 首先在我们学习css之前先来思考一个问题,为什么html标签上不直接 ...
- 动车上的书摘-java对象流与序列化
摘要: 摘要: 原创出处: http://www.cnblogs.com/Alandre/ 泥沙砖瓦浆木匠 希望转载,保留摘要,谢谢! 钢笔不限贵便宜,书法是来自心对手的交流.-泥沙砖瓦浆木匠 一.对 ...
- TOMCAT源码分析(转)
前言: 本文是我阅读了TOMCAT源码后的一些心得. 主要是讲解TOMCAT的系统框架, 以及启动流程.若有错漏之处,敬请批评指教!建议: 毕竟TOMCAT的框架还是比较复杂的, 单是从文字上 ...
- SpringBoot系列——Thymeleaf模板
前言 thymeleaf是springboot官方推荐使用的java模板引擎,在springboot的参考指南里的第28.1.10 Template Engines中介绍并推荐使用thymeleaf, ...
- Python爬虫之诗歌接龙
介绍 本文将展示如何利用Python爬虫来实现诗歌接龙. 该项目的思路如下: 利用爬虫爬取诗歌,制作诗歌语料库: 将诗歌分句,形成字典:键(key)为该句首字的拼音,值(value)为该拼音对 ...
- 使用VSCode如何调试C#控制台程序_1
A-环境安装 https://www.microsoft.com/net/download 下载 .NET Core SDK Installer: https://www.microsoft.com/ ...
- 第一册:lesson thirty seven。
原文: Making a bookcase. A:You are working hard,George. What are you doing . B:I am making a bookcase. ...