山东理工大学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 ...
随机推荐
- ARM debian的图形界面安装
这里图形界面的安装比较简单,启动系统后,登录到root账户,首先要执行更新源的命令:apt-get update 然后直接执行下面的动作: 直接安装LXDE即可: 指令: apt-get insta ...
- java中调用三方接口post传参时map和jsonobject的区别转换
post方法名及参数为:(具体方法可参考https://www.cnblogs.com/mufengforward/p/10510337.html) public static String doPo ...
- 简单聊一聊那些svg的沿路径运动
之前遇见动画就很想用css实现,显然有些效果是我们力所不能及,实现起来麻烦,效果不好,让人捉急.其实归结起来,不同的动画有自己的优势,根据实际情况进行取舍.本文就告诉大家如何用SVG写出个简单动画.就 ...
- vue 关于数组和对象的更新
在日常开发中,我们用的最多的就是 绑定数据 <div v-for="item in data" :key="item.id"> <!-- 内容 ...
- ionic3 ionic serve build fail Error: webpackJsonP is not defined
ionic升级后发现 ionic serve 跑起来项目出现一下错误: Runtime Error: webpackJsonP is not definedStack: @http://localho ...
- .Net 环境下比较各种数据库插入操作的性能
1.简介 再说Windows的异步I/O操作前,先聊聊一些题外话,能帮助我们更好的理解异步I/O操作,常规的Web程序,当用户发起一次请求,当请求通过管道到达客户端的这个过程,会唤起一个线程池线程(后 ...
- Linux安全配置
注释掉系统不需要的用户和用户组 vi /etc/passwd #adm:x:3:4:adm:/var/adm:/sbin/nologin #lp:x:4:7:lp:/var/spool/lpd:/sb ...
- 关于css,js放置位置的问题
一天,小明正在网上查找资料,项目中遇到的问题需要通过查阅资料来解决,他看到一个标题很有意思,觉得这应该是他要找的答案,于是他就点了进去,结果进入网站后几秒钟的时间,网页还是一片空白,过了好久才加载完成 ...
- 数据读取(SQL)与文本写入(fileStream)
要求:从三个不同服务器中取数,对最近10的历史数据进行去重,写出到文本. 1.读取. public static DataTable ExecuteSql(string connectString, ...
- 使用Python开发chrome插件
本文由 伯乐在线 - xianhu 翻译,Daetalus 校稿.未经许可,禁止转载!英文出处:pythonspot.com.欢迎加入翻译小组. 谷歌Chrome插件是使用HTML.JavaScrip ...