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代码 及分析的更多相关文章

  1. [python]Python代码安全分析工具(Bandit)

    简介: Bandit是一款Python源码分析框架,可用于Python代码的安全性分析.Bandit使用标准库中的ast模块,将Python源码解析成Python语法节点构成的树.Bandit允许用户 ...

  2. python 代码性能分析 库

    问题描述 1.Python开发的程序在使用过程中很慢,想确定下是哪段代码比较慢: 2.Python开发的程序在使用过程中占用内存很大,想确定下是哪段代码引起的: 解决方案 使用profile分析分析c ...

  3. 朴素贝叶斯算法简介及python代码实现分析

    概念: 贝叶斯定理:贝叶斯理论是以18世纪的一位神学家托马斯.贝叶斯(Thomas Bayes)命名.通常,事件A在事件B(发生)的条件下的概率,与事件B在事件A(发生)的条件下的概率是不一样的:然而 ...

  4. 使用 profile 进行python代码性能分析

    定位程序性能瓶颈 对代码优化的前提是需要了解性能瓶颈在什么地方,程序运行的主要时间是消耗在哪里,对于比较复杂的代码可以借助一些工具来定位,python 内置了丰富的性能分析工具,如 profile,c ...

  5. ACM 做题过程中的一些小技巧。

    ACM做题过程中的一些小技巧. 1.一般用C语言节约空间,要用C++库函数或STL时才用C++; cout.cin和printf.scanf最好不要混用. 2.有时候int型不够用,可以用long l ...

  6. 各大ACM OJ网址

    做快乐的程序员 以你的条件,你不必追求优秀,但你可以做到良好. 各大OJ网址 ACM OJ Collection(排名不分先后): 中国:(China) 华东地区: 浙江: 杭州电子科技大学(HDU) ...

  7. 用PHP语言刷OJ题

    平常在学校都是用C,C++,Java来刷OJ题,把AC的题用不同的语言再AC一次,基本相当于翻译而已.看到学校的OJ支持提交PHP代码,于是尝试了一下. 首先,得会使用PHP,但是你如果在看这篇博客, ...

  8. 一起来写2048(160行python代码)

    前言: Life is short ,you need python. --Bruce Eckel 我与2048的缘,不是缘于一个玩家,而是一次,一次,重新的ACM比赛.四月份校赛初赛,第一次碰到20 ...

  9. 一起写2048(160行python代码)

    前言: Life is short ,you need python. --Bruce Eckel 我与2048的缘,不是缘于一个玩家.而是一次,一次,重新的ACM比赛.四月份校赛初赛,第一次碰到20 ...

随机推荐

  1. 机器学习入门12 - 分类 (Classification)

    原文链接:https://developers.google.com/machine-learning/crash-course/classification/ 1- 指定阈值 为了将逻辑回归值映射到 ...

  2. Jexus~mono中使用StackExchange.redis的问题

    在windows平台的vs里,添加包包时,可以选择StackExchange.redis,而如果你的应该程序需要部署到linux的mono环境上,使用这个StackExchange.redis是不行的 ...

  3. DWR第二篇之逆向Ajax

    1. 本示例在第一篇架构基础上添加代码 2. 首先修改web.xml里dwr的servlet配置: <!-- 配置dwr请求的servlet --> <servlet> < ...

  4. 从前端界面开发谈微信小程序体验

    本文由云+社区发表 作者介绍:练小习,2011年加入搜狐,负责搜狐相册的产品策划与前端开发.2015年后加入腾讯 ISUX (社交用户体验设计部),目前主要负责腾讯云的UI开发工作,专注于人机交互,有 ...

  5. Gradle nexus 解决开发机器不连网无法下载gradle插件问题

    在用gradle时常规配置如下(D:\gradle-4.9\init.d\init.gradle文件,没有这个文件时自建): ext { nexus = 'http://192.168.127.128 ...

  6. Apache-httpd.conf详解

    ## Apache服务器主配置文件.  包括服务器指令的目录设置.# 详见 <URL:http://www.apache.org/docs/> ## 请在理解用途的基础上阅读各指令.## ...

  7. CPU上下文切换

    CPU上下文切换包括进程上下文切换.线程上下文切换及中断上下文切换,当任务进行io或发生时间片事件及发生中断(如硬件读取完成)时,就会进入内核态,发生CPU上下文切换. 进程上下文切换,进程的上下文信 ...

  8. IFS简单说明

    bash&shell系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html bash下的很多命令都会分割单词,绝大多数时候默认是采用空格作 ...

  9. iOS面试准备之思维导图

    以思维导图的方式对iOS常见的面试题知识点进行梳理复习,文章xmind点这下载,文章图片太大查看不了也点这下载 你可以在公众号 五分钟学算法 获取数据结构与算法相关的内容,准备算法面试 公众号回复 g ...

  10. 反爬虫——使用chrome headless时一些需要注意的细节

    以前我们介绍过chrome headless的用法(https://www.cnblogs.com/apocelipes/p/9264673.html). 今天我们要稍微提一下其中一个细节. 反爬和w ...