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. 关于动画的几种状态表示的含义以及能够使用2d动画表述为什么要使用3d动画表述

    transform 四种转换 translate 位置scale 缩放rotate 旋转skew 倾斜 以上四种转换方式是比较特殊的,其实他们都是由matrix 矩阵转换来: animation的五种 ...

  2. 解决android sdk 运行出现 could not install *smartsocket* listener: cannot bind to 127.0.0.1:5037:的问题

    ionic3项目,在添加android平台后,cordova run android 出现 以下问题: error: could not install *smartsocket* listener: ...

  3. C++版 - 剑指offer 面试题16:反转链表(Leetcode 206: Reverse Linked List) 题解

    面试题16:反转链表 提交网址: http://www.nowcoder.com/practice/75e878df47f24fdc9dc3e400ec6058ca?tpId=13&tqId= ...

  4. Ambari集群移动现有复制到另外地方或更改ip地址,导致各项服务组件上为黄色问号代表心跳丢失的解决方案(图文详解)(博主推荐)

    前言 最近,是在做集群搬移工作,大家肯定会遇到如下的场景. (1) 比如,你新购买的电脑,初步者学习使用Ambari集群.从旧电脑复制到新电脑这边来. (2) 比如,你公司Ambari集群的ip,因业 ...

  5. Unity中雾效的开启

    原文:https://blog.csdn.net/Rhett_Yuan/article/details/54425236 1.对于雾效的开启在新版的Unity中通过界面菜单Windows->Li ...

  6. go捕获Ctrl+C信号

    我们希望当服务器接收到一个 SIGTERM 信号时能够自动关机,或者做一些善后的操作,以下是实现的方法 package main import ( "os" "os/si ...

  7. 自定义了一个email模块,符合大多数人的使用习惯

    # coding: utf-8 import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text i ...

  8. 数据挖掘(二)——Knn算法的java实现

    1.K-近邻算法(Knn) 其原理为在一个样本空间中,有一些已知分类的样本,当出现一个未知分类的样本,则根据距离这个未知样本最近的k个样本来决定. 举例:爱情电影和动作电影,它们中都存在吻戏和动作,出 ...

  9. WPF 绕圈进度条(一)

    在设计界面时,有时会遇到进度条,本次讲解如何设计自定义的绕圈进度条,直接上代码: 1.控件界面 <UserControl x:Class="ProgressBarControl&quo ...

  10. 解决MyEclipse中install new software问题

    eclipse中点击help可以直接找到install new software选项进行安装插件,但是在Myeclipse中help没有这个选项,如下提供几种解决方法 Windows-preferen ...