zoukankan      html  css  js  c++  java
  • 山东理工大学SDUT

    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==['0']:
            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 的值就是 : ['1', '3', '4']
    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、统计次数问题
  • 相关阅读:
    久未更 ~ 四之 —— Vsftpd出现 Failed to start Vsftpd ftp daemon错误
    久未更 ~ 三之 —— CardView简单记录
    久未更 ~ 二之 —— TextView 文字省略
    久未更 ~ 一之 —— 关于ToolBar
    【UVA1636】决斗Headshot
    【NOIP模拟】花园
    【UVA1262】Password
    【UVA10820】交表
    【UVA1635】哑元
    【UVA12716】GCD和XOR
  • 原文地址:https://www.cnblogs.com/xqxacm/p/8296308.html
Copyright © 2011-2022 走看看