跳到正文

个人记录

NFLSOJ Python 题解

jerrywcy约 41 分钟
原文
文章信息与版本

文章信息

发布
2019年6月17日
收录
2025年12月12日
更新
2026年11月15日
篇幅
约 41 分钟
获赞
1

版本

  1. v1当前

章节1 输入、输出

A+B Problem

Python
a,b=map(int,input().split())
print(a+b)

Hello World!

Python
print("Hello World!")

打印小写字母表

Python
print("abcdefghijklm")
print("nopqrstuvwxyz") 
print("zyxwvutsrqpon")
print("mlkjihgfedcba")

章节2 算术运算和赋值语句

混合运算

Python
a,b=map(int,input().split())
print((a+b)*(a-b))

求一个数的立方

Python
a=int(input())
print(a**3)

求长方形面积和周长

Python
a,b=map(int,input().split())
print(a*b,2*(a+b))

计算线段长度

Python
import math

xa,ya=map(int,input().split())
xb,yb=map(int,input().split())
print("%.3f"%(math.sqrt((abs(xa-xb))**2+(abs(ya-yb))**2)))

求三角形周长

Python
import math

def dis(xa,ya,xb,yb):
    return math.sqrt((abs(xa-xb))**2+(abs(ya-yb))**2)
x1,y1,x2,y2,x3,y3=map(int,input().split())
print("%.2f"%(dis(x1,y1,x2,y2)+dis(x2,y2,x3,y3)+dis(x3,y3,x1,y1)))

手表

Python
S=int(input())
h=S//3600
m=S/60%60
s=S%60
print("%d:%d:%d"%(h,m,s))

铺地砖

Python
n,m=map(int,input().split())
print((n//m)**2)

拼接

Python
n=int(input())
print((n-1)*4)

服装搭配I

Python
m,n=map(int,input().split())
print(m*n)

魔方

Python
n=int(input())
print(8)
print(12*(n-2))
print(6*(n-2)*(n-2))

分糖果

Python
a,b,c,d,e=map(int,input().split())

e+=a//3
b+=a//3
a//=3

a+=b//3
c+=b//3
b//=3

b+=c//3
d+=c//3
c//=3

c+=d//3
e+=d//3
d//=3

d+=e//3
a+=e//3
e//=3

print(a,b,c,d,e)

求任意三位数各个数位上数字的和

Python
x=int(input())
ans=0
while x:
    ans+=x%10
    x//=10
print(ans)

输入一个三位数,把个位和百位对调后输出

Python
x=int(input())
a=0
while x:
    a=a*10+x%10
    x//=10
print(a)

倒序输出一个四位整数

Python
x=int(input())
a=0
while x:
    a=a*10+x%10
    x//=10
print(a)

算算和是多少

Python
a=int(input())
b=0
x=a
while x:
    b=b*10+x%10
    x//=10
print(a+b)

章节3 关系、逻辑运算与选择语句

两数比大小

Python
a,b=map(int,input().split())
print(max(a,b))

判断奇偶数

Python
a=int(input())
if a%2==0:
    print("y e s")
else:
    print("n o")

交易预期

Python
p,q,m=map(int,input().split())
if p<=m and m<=q:
    print("Yes")
else:
    print("No")

恐龙园买门票

Python
a=float(input())
if a<1.3:
    print(60)
else:
    print(120)

心系南方灾区

Python
m,n=map(int,input().split())
print((m+n-1)//n)

求三个数的最大数

Python
a,b,c=map(int,input().split())
print(max(a,max(b,c)))

三数最小数

Python
a,b,c=map(int,input().split())
print(min(a,min(b,c)))

求任意三位数打乱次序后的最大值

Python
x=int(input())
a=[x//100,x//10%10,x%10]
a.sort()
print(a[2]*100+a[1]*10+a[0])

判断三个整数是否相邻

Python
a=[int(i) for i in input().split()]
a.sort()
if a[0]+1==a[1] and a[1]+1==a[2]:
    print("TRUE")
else:
    print("FALSE")

判断某年某月的天数

Python
def ck(y):
    if y%400==0:
        return 1
    elif y%100==0:
        return 0
    else:
        return y%4==0
month=[0,31,0,31,30,31,30,31,31,30,31,30,31]
y,m=map(int,input().split())
if ck(y):
    month[2]=29
else:
    month[2]=28
print(month[m])

比赛日期

Python
def ck(y):
    if y%400==0:
        return 1
    elif y%100==0:
        return 0
    else:
        return y%4==0
month=[0,31,0,31,30,31,30,31,31,30,31,30,31]
m,d,y=map(int,input().split())
if ck(y):
    month[2]=29
else:
    month[2]=28
d+=1
if d>month[m]:
    d=1
    m+=1
if m>12:
    m=1
    y+=1
print("%d/%d/%d"%(m,d,y))

第一个人大?

Python
y,m,d=map(int,input().split())
t1=y*10000+m*100+d
y,m,d=map(int,input().split())
t2=y*10000+m*100+d
if t1<t2:
    print("Yes")
else:
    print("No")

能否构成直角三角形

Python
a,b,c=map(int,input().split())
x=[a,b,c]
x.sort()
a=x[0];b=x[1];c=x[2];
if a*a+b*b==c*c:
    print("%.1f"%(a*b/2))
else:
    print("No")

三角形类别

Python
x=[int(i) for i in input().split()]
x.sort()
a=x[0]
b=x[1]
c=x[2]
if a+b<=c:
    print("no")
elif a*a+b*b>c*c:
    print("ruijiao")
elif a*a+b*b==c*c:
    print("zhijiao")
elif a*a+b*b<c*c:
    print("dunjiao")

时间转换

Python
t=int(input())
h=t//3600
m=t//60%60
s=t%60
print("%02d:%02d:%02d"%(h,m,s))

小 X 与机器人 (betago)

Python
a1,a2,b1,b2=map(int,input().split())
ss=0
sy=0
if abs(a1-b1)==18:
    ss=18+a2-1+b2-1
    sy=18+19-a2+19-b2
if abs(a2-b2)==18:
    ss=18+a1-1+b1-1
    sy=18+19-a1+19-b1 
if a1==b1:
    ss=abs(a2-b2)
if a2==b2:
    ss=abs(a1-b1)
if ss+sy==0:
    ss=abs(a1-b1)+abs(a2-b2)
if ss>sy and sy!=0:
    print(sy) 
else:
    print(ss)

章节4 循环语句for

编程求1+3+5+…+n

Python
n=int(input())
ans=0
for i in range(1,n+1,2):
    ans+=i
print(ans)

编程求解2+4+6+…+n

Python
n=int(input())
ans=0
for i in range(2,n+1,2):
    ans+=i
print(ans)

求100+97+……+4+1的值。

Python
ans=0
for i in range(1,101,3):
    ans+=i
print(ans)

分别求奇数和偶数和

Python
n=int(input())
a=[0,0]
for i in range(1,n+1):
    x=int(input())
    a[x%2]+=x
print(a[1])
print(a[0])

判奇偶求和

Python
n=int(input())
ans=0
if n%2==1:
    for i in range(2,n+1,2):
        ans+=i
else:
    for i in range(1,n+1):
        if n%i==0:
            ans+=i
print(ans)

编程求1+1/2+1/3+…+1/n

Python
n=int(input())
ans=0.0
for i in range(1,n+1):
    ans+=1/i
print("%.3f"%(ans))

求函数值

Python
import math
n,x=map(int,input().split())
ans=0.0
ans+=x
for i in range(1,n+1):
    ans=math.sqrt(i+ans)
print("%.3f"%(ans))

同因查找

Python
for i in range(20,1001):
    if i%2==0 and i%3==0 and i%7==0:
        print(i)

求满足条件的整数个数

Python
n=int(input())
ans=0
for i in range(1,n+1):
    if i%3==2 and i%5==3 and i%7==2:
        ans+=1
print(ans)

打折优惠

Python
n=int(input())
ans=0.0
a=[int(i) for i in input().split()]
for i in a:ans+=i
if ans>100:
    ans=100+0.9*(ans-100)
print("%.2f"%(ans))

选裙子

Python
n=int(input())
ans=0
for i in input().split():ans+=int(i)
print((ans-1)%n+1)

自由落体

Python
m,n=map(int,input().split())
h=float(m)
dis=0.0
for i in range(1,n+1):
    dis+=h
    h/=2
    dis+=h
dis-=h
print("%.2f %.2f"%(h,dis))

咪咪的智慧

Python
n,t=map(int,input().split())
a=[int(i) for i in input().split()]
ans=0
for i in a:
    if i<t:
        ans+=1
print(ans)

寻找雷劈数

Python
for i in range(1000,10000):
    a=i//100
    b=i%100
    if (a+b)**2==i:
        print(i)

判断素数

Python
import math

x=int(input())
if x<=1:
    print("F")
    exit(0)

for i in range(2,int(math.sqrt(x))+1):
    if x%i==0:
        print("F")
        exit(0)
print("T")

二维矩阵数字的和

Python
n=int(input())
ans=0
for i in range(1,n+1):
    ans+=i*(2*i-1)
print(ans)

章节5 循环语句while

编程求1+3+5+…+n

Python
n=int(input())
ans=0
for i in range(1,n+1,2):
    ans+=i
print(ans)

编程求解2+4+6+…+n

Python
n=int(input())
ans=0
for i in range(2,n+1,2):
    ans+=i
print(ans)

角谷猜想

Python
n=int(input())
cnt=0
while n!=1:
    if n%2==0:n//=2
    else:n=n*3+1
    cnt+=1
print(cnt)

求恰好使s=1+1/2+1/3+…+1/n的值大于X时n的值。

Python
x=int(input())
ans=0.0
i=0
while ans<=x:
    i+=1
    ans+=1/i
print(i)

至少多少

Python
m=int(input())
i=0
s=0
while s<m:
    i+=1
    s+=2*i-1
print(i)

数字5的亲戚们

Python
n=int(input())
ans=0
for i in range(5,n+1,5):
    tmp=i
    while tmp:
        if tmp%10==5:
            ans+=1
            break
        tmp//=10
print(ans)

打折优惠

Python
n=int(input())
ans=0.0
a=[int(i) for i in input().split()]
for i in a:ans+=i
if ans>100:
    ans=100+0.9*(ans-100)
print("%.2f"%(ans))

求S的值

Python
print(5488)

级数求和

Python
m=int(input())
i=0
add=0
s=0
while s<=m:
    i+=1
    add+=i
    s+=add
print(i-1,s-add)

求零件个数

Python
#print(173)
for i in range(100,200):
    if i%3==2 and i%5==3 and i%7==5:
        print(i)
        exit(0)

统计大写英文字母的个数

Python
x=input()
ans=0
for i in x:
    if 'A'<=i and i<='Z':
        ans+=1
print(ans)

统计字符的个数

Python
x=input()
cnt1=cnt2=cnt3=0
for i in x:
    if 'A'<=i and i<='Z':
        cnt1+=1
    elif 'a'<=i and i<='z':
        cnt2+=1
    elif '0'<=i and i<='9':
        cnt3+=1
print(cnt1,cnt2,cnt3)

数列求和2

Python
def p(x):
    if x>=0:
        print("%d+"%(x),end='')
    else:
        print("(%d)+"%(x),end='')
x1,x2,x3,xn=map(int,input().split())
d=x2-x1
ans=(x1+xn)*((xn-x1)//d+1)//2
p(x1)
p(x2)
p(x3)
if x3+d!=xn:
    print("...+",end='')
if xn>=0:
    print("%d"%(xn),end='')
else:
    print("(%d)"%(xn),end='')
print("=%d"%(ans))

章节6 列表list

序列 统计

Python
n=int(input())
a=[]
for i in range(0,n):
    x=int(input())
    a.append(x)
m=int(input())
ans=0
for i in a:
    if i==m:
        ans+=1
print(ans)

序列 求平均年龄

Python
n=int(input())
s=0
for i in range(0,n):
    x=int(input())
    s+=x
print("%.2f"%(s/n))

序列 逆序

Python
m=int(input())
a=[int(i) for i in input().split()]
a.reverse()
for i in a:
    print(i,end=' ')

序列 输出奇数和偶数

Python
n=int(input())
a=[int(i) for i in input().split()]
odd=[]
even=[]
for i in a:
    if i%2==0: even.append(i)
    else: odd.append(i)
for i in odd:print(i,end=' ')
print()
for i in even:print(i,end=' ')

序列 最大数的位置

Python
n=int(input())
a=[int(i) for i in input().split()]
maxv=0
for i in a:maxv=max(maxv,i)
for i in range(0,n):
    if a[i]==maxv:
        print(i+1)

序列 找找谁的身高超过全家的平均身高

Python
n=int(input())
a = [int(x) for x in input().split()]
ans=0.0
for i in a:
    ans+=i
ans=ans/n
print("Aver=%0.1f"%(ans))
for i in range(0,n):
    if (a[i]>=ans):
        print("%d:%d"%(i+1,a[i]),end=' ')

列表元素的移动

Python
n=int(input())
a = [int(i) for i in input().split()]
b=[]
x=int(input())
if (x>1):
    b+=(a[0:x-1])
if (x<n):
    b+=(a[x:])
b.append(a[x-1])
for i in b:
    print(i,end=' ')

列表元素的插入

Python
n=int(input())
a=[int(i) for i in input().split()]
index=int(input())
obj=int(input())
a.insert(index-1,obj)
for i in a:
    print(i,end=' ')

列表元素的删除

Python
n=int(input())
a=[int(i) for i in input().split()]
x=int(input())
for i in range(0,n):
    if (i!=x-1):
        print(a[i],end=' ')

列表 Fish学数学

Python
n=int(input())
a=[]
for i in range(1,n+1):
    a.append(int(input()))
ans=0
for i in range(0,n):
    for j in range(i+1,n):
        if (a[j]<a[i]):
            ans+=1
print(ans)

最大最小

Python
def s(x):
    ret=0
    while (x):
        ret+=x%10
        x//=10
    return ret

l=int(input())
d=int(input())
x=int(input())
minv=10010
maxv=0
for i in range(l,d+1):
    if (s(i)==x):
        minv=min(minv,i)
        maxv=max(maxv,i)
print(minv)
print(maxv)

列表 倒数第二小整数

Python
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
i=len(a)-1
while (a[i]==a[i-1]):
    i-=1
print(a[i-1])

下载电影

Python
n,m=map(int,input().split())
a=[int(i) for i in input().split()]
s=0
ans=0.0
for i in range(0,m):
    s+=a[i]
ans=max(ans,s/m)
for i in range(m,n):
    s=s+a[i]-a[i-m]
    ans=max(ans,s/m)
print("%0.2f"%(ans))

赛马

Python
n=int(input())
a1=[int(i) for i in input().split()]
b1=[int(i) for i in input().split()]
x=0
y=0
z=0
a2=[int(i) for i in input().split()]
b2=[int(i) for i in input().split()]
for i in range(0,n):
    a=a1[a2[i]-1]
    b=b1[b2[i]-1]
    if a>b:x+=1
    elif a==b:y+=1
    else: z+=1
print(x,y,z)

草料开支

Python
n,q=map(int,input().split())
a=[0]*(n+1)
for i in range(1,n+1):
    x=int(input())
    a[i]=a[i-1]+x;
for i in range(0,q):
    s,e=map(int,input().split())
    print(a[e]-a[s-1])

奶牛式乘法

Python
a,b=map(int,input().split())
ans=0
tmpa=a
while tmpa:
    x=tmpa%10
    tmpb=b
    while tmpb:
        y=tmpb%10
        ans+=x*y
        tmpb//=10
    tmpa//=10
print(ans)

完全图

Python
import math

def dis(x1,y1,x2,y2):
    return math.sqrt((x2-x1)**2+(y2-y1)**2)

n=int(input())
x=[]
y=[]
for i in range(0,n):
    xx,yy=map(int,input().split())
    x.append(xx)
    y.append(yy)
ans=0.0
for i in range(0,n-1):
    for j in range(i+1,n):
        ans+=dis(x[i],y[i],x[j],y[j])
print("%.2f"%(ans))

前缀和

Python
n=int(input())
a=list(map(int,input().split()))
s=[0]
for i in range(0,n):
    s.append(s[i]+a[i])
q=int(input())
for i in range(1,q+1):
    l,r=map(int,input().split())
    print(s[r]-s[l-1])

一年中的第几天

Python
def leap(year):
    if (year%400==0):return 1
    if (year%100==0):return 0
    return year%4==0
a=[0,31,0,31,30,31,30,31,31,30,31,30,31]
y,m,d=map(int,input().split("-"))
if (leap(y)):a[2]=29
else:a[2]=28
ans=d
for i in range(1,m):
    ans+=a[i]
print(ans)

二维矩阵数字的和

Python
n=int(input())
ans=0
for i in range(1,n+1):
    ans+=i*(2*i-1)
print(ans)

求N个整数的平均数、众数和中位数

Python
n=int(input())
a=[int(i) for i in input().split()]
a=[0]+a

s=0
for i in a:s+=i
print("%.2f"%(s/n),end=' ')

m={}
maxv=0
pos=0
for i in a:
    m[i]=m.get(i,0)+1
    if m[i]>maxv:
        maxv=m[i]
        pos=i
print(pos,end=' ')

a.sort()
if n%2==0:
    print("%.1f"%((a[n//2]+a[n//2+1])/2))
else:
    print("%.1f"%(a[n//2+1]))

章节7 字符串

统计数字字符个数

Python
s=input()
ans=0
for i in s:
    if i>='0' and i<='9':
        ans+=1
print(ans)

数字和

Python
n=int(input())
s=0
while n!=0:
    s+=n%10
    n//=10
print(s)

大小写转换

Python
s=input()
ret=""
for x in s:
    if ord(x)>=ord('A') and ord(x)<=ord('Z'):
        ret=ret+chr(ord(x)-ord('A')+ord('a'))
    elif ord(x)>=ord('a') and ord(x)<=ord('z'):
        ret=ret+chr(ord(x)-ord('a')+ord('A'))
    else:
        ret+=x
print(ret)

扫描识别

Python
s=input()
ret=""
for x in s:
    d=ord(x)
    if d==ord('O'):ret+='0'
    elif d==ord('l'):ret+='1'
    elif d==ord('Z'):ret+='2'
    elif d==ord('S'):ret+='5'
    elif d==ord('b'):ret+='6'
    elif d==ord('B'):ret+='8'
    elif d==ord('q'):ret+='9'
    else:ret+=x
print(ret)

电报文字

Python
s=input()
ss=""
for x in s:
    if x.islower():
        ss+=chr((ord(x)-ord('a')+1)%26+ord('a'))
    else:
        ss+=x
print(ss)

字符串压缩

Python
s=input()
n=len(s)
s+=" "
ss=""
i=0
while i<n:
    j=i
    while s[j+1]==s[j]:j+=1
    num=j-i+1
    if num==1:ss+=s[j]
    else:
        while num:
            ss+=chr(num+ord('0'))
            num//=10
        ss+=s[j]
    i=j+1
print(ss)

破译邮件

Python
def deal(s):
    i=0
    while i<len(s):
        if s[i]=='-':i+=1
        elif s[i]=='#':
            print(" ",end='')
            i+=1
        elif s[i].isdigit():
            tmp=0
            while i<len(s) and s[i].isdigit():
                tmp=tmp*10+ord(s[i])-ord('0')
                i+=1
            tmp-=1
            print(chr(tmp+ord('A')),end='')
            
    print()

n=int(input())
for _ in range(0,n):
    s=input()
    deal(s)

判断是否构成回文

Python
s=input()
s=s[0:(len(s)-1)]
ss=reversed(list(s))
if list(s)==list(ss):
    print("TRUE")
else:
    print("FALSE")

砳砳的图形

Python
s=[]
cnt=[]
for i in range(4):
    s.append(input())
for i in range(30):
    cnt.append(0)
for i in range(4):
    for j in s[i]:
        if not j.isupper():
            continue
        cnt[ord(j)-ord('A')]+=1

for i in range(max(cnt),0,-1):
    __buff=''
    for j in range(26):
        if cnt[j]>=i:
            print(__buff,end='')
            print('*',end='')
            __buff=''
        else:
            __buff+=' '
        __buff+=' '
    print()

for i in range(26):
    print(chr(i+ord('A')),end='')
    if i!=25:
        print(' ',end='')

奇偶位互换

Python
n=int(input())
for _ in range(0,n):
    s=input()
    ss=""
    for i in range(0,len(s)):
        ss+=s[i^1]
    print(ss)

章节8 字典dict

统计数字字符个数

Python
s=input()
ans=0
for i in s:
    if i>='0' and i<='9':
        ans+=1
print(ans)

火柴棒等式(简版)

Python
s=input()
d={'0':6,'1':2,'2':5,'3':5,'4':4,'5':5,'6':6,'7':3,'8':7,'9':6,'+':2,'=':2}
ans=0
for i in s:
    ans+=d[i]
print(ans)

扫描识别

Python
s=input()
ret=""
for x in s:
    d=ord(x)
    if d==ord('O'):ret+='0'
    elif d==ord('l'):ret+='1'
    elif d==ord('Z'):ret+='2'
    elif d==ord('S'):ret+='5'
    elif d==ord('b'):ret+='6'
    elif d==ord('B'):ret+='8'
    elif d==ord('q'):ret+='9'
    else:ret+=x
print(ret)

小 X 与机器人 2 (sihuo)

Python
x,y=list(),list()
s1,s2,t=int(),int(),int()
x.append(-1000)
y.append(-1000)
for i in range(1,5):
    a,b=map(int,input().split())
    x.append(a)
    y.append(b)
x.sort()
y.sort()
t=1
if ((x[1]==x[2])and(x[3]==x[2])and(x[3]==x[4])or(y[1]==y[2])and(y[3]==y[2])and(y[3]==y[4])):
    print('zhisi')
    exit(0)
for i in range(1,4):
    for j in range(i+1,5):
        if (x[i]==x[j]):
            s1+=1;
        if (y[i]==y[j]):
            s2+=1;
if ((s1==2)and(s2==2)):
    print('fangsi')
    exit(0)
if(s1==3):
    for i in range(1,4):
        if (y[i]==y[i+1]):
            if (i==2):
                print('dingsi')
                exit(0)
            else:
                print('qusi')
                exit(0)
if (s2==3):
    for i in range(1,4):
        if (x[i]==x[i+1]):
            if (i==2):
                print('dingsi')
                exit(0)
            else:
                print('qusi')
                exit(0)
if ((s1==1)or(s2==1)):
    print('wansi')

章节9 自定义函数

求正整数2和n之间的完全数

Python
def perfect(x):
    ans=1
    for i in range(2, x//2+1):
        if x % i == 0:
            ans += i
    return ans == x
n= int(input())
for i in range(2, n+1):
    if perfect(i):
        print(i)

素数个数

Python
p = [0]*50010
n = int(input())
ans = 0
for i in range(2,n+1):
    if not p[i]:
        ans += 1
        for j in range(i,n//i+1):
            p[i * j] = 1
print(ans)

最大数max(x,y,z)

Python
def mx(a,b,c):
    return max(a,max(b,c))
a,b,c=map(int,input().split())
print("%0.3f"%(mx(a,b,c)/(mx(a+b,b,c)*max(a,b,b+c))))

绝对素数

Python
def rev(x):
    return x//10+x%10*10
def prime(x):
    for i in range(2,x):
        if x%i==0:
            return 0
    return 1
for i in range(10,100):
    if prime(i) and prime(rev(i)):
        print(i)

回文三位素数

Python
def pal(x):
    tmp=x
    xx=0
    while tmp:
        xx=xx*10+tmp%10
        tmp//=10
    return xx==x
def prime(x):
    for i in range(2,x):
        if x%i==0:
            return 0
    return 1

for i in range(100,1000):
    if pal(i) and prime(i):
        print(i)

哥德巴赫猜想

Python
print("""6=3+3
8=3+5
10=3+7
12=5+7
14=3+11
16=3+13
18=5+13
20=3+17
22=3+19
24=5+19
26=3+23
28=5+23
30=7+23
32=3+29
34=3+31
36=5+31
38=7+31
40=3+37
42=5+37
44=3+41
46=3+43
48=5+43
50=3+47
52=5+47
54=7+47
56=3+53
58=5+53
60=7+53
62=3+59
64=3+61
66=5+61
68=7+61
70=3+67
72=5+67
74=3+71
76=3+73
78=5+73
80=7+73
82=3+79
84=5+79
86=3+83
88=5+83
90=7+83
92=3+89
94=5+89
96=7+89
98=19+79
100=3+97""")

短信计费

Python
import math

n=int(input())
ans=0
for i in range(0,n):
    x=int(input())
    ans+=math.ceil(x/70)
print(ans/10)

甲流病人初筛

Python
def isill(s,t,b):
    if t>=37.5 and b:
        print(s)
        return 1
    return 0

n=int(input())
ans=0
for i in range(0,n):
    inp=input().split()
    ans+=isill(inp[0],float(inp[1]),int(inp[2]))
print(ans)

两个自然数M和N的最小公倍数。

Python
def gcd(x,y):
    if y==0: return x
    else: return gcd(y,x%y)
n,m=map(int,input().split())
print(n*m//gcd(n,m))

输出m和n范围内的完全数(完美数)

Python
a=[6,28,496,8128]
m,n=map(int,input().split())
for i in a:
    if m<=i and n>=i:
        print(i,end=' ')

全体集合

Python
def dis(x1,y1,x2,y2):
    return abs(x1-x2)+abs(y1-y2)

a=[0]*1010
b=[0]*1010
c=[0]*1010
d=[0]*1010
n,m=map(int,input().split())
for i in range(0,n):
    a[i],b[i]=map(int,input().split())
for i in range(0,m):
    c[i],d[i]=map(int,input().split())
for i in range(0,n):
    minv=1926081719260817
    minj=0
    for j in range(0,m):
        dist=dis(a[i],b[i],c[j],d[j])
        if dist<minv:
            minv=dist
            minj=j
    print(minj+1)

小 X 与机器人 2 (sihuo)

Python
x,y=list(),list()
s1,s2,t=int(),int(),int()
x.append(-1000)
y.append(-1000)
for i in range(1,5):
    a,b=map(int,input().split())
    x.append(a)
    y.append(b)
x.sort()
y.sort()
t=1
if ((x[1]==x[2])and(x[3]==x[2])and(x[3]==x[4])or(y[1]==y[2])and(y[3]==y[2])and(y[3]==y[4])):
    print('zhisi')
    exit(0)
for i in range(1,4):
    for j in range(i+1,5):
        if (x[i]==x[j]):
            s1+=1;
        if (y[i]==y[j]):
            s2+=1;
if ((s1==2)and(s2==2)):
    print('fangsi')
    exit(0)
if(s1==3):
    for i in range(1,4):
        if (y[i]==y[i+1]):
            if (i==2):
                print('dingsi')
                exit(0)
            else:
                print('qusi')
                exit(0)
if (s2==3):
    for i in range(1,4):
        if (x[i]==x[i+1]):
            if (i==2):
                print('dingsi')
                exit(0)
            else:
                print('qusi')
                exit(0)
if ((s1==1)or(s2==1)):
    print('wansi')
原文