study Python 25day

while True:
    try:
        a,b,c,d=input(),list(map(int,input().split())),input(),list(map(int,input().split()))
        print("".join(map(str,sorted(list(set(b+d))))))
    except:
        break

while True:
    try:
        a=int(input())
        b=int(input())
        print(a+b)
    except:
        break

#-*-coding:utf-8-*-
#####This  is  a  modification  of  Hunter21's######
 
def handle(pre_station, in_station, after_station):
    if not pre_station and not in_station:  # 没有待进站的,也没有待出站的车,一种情况产生了
        result.append(" ".join(after_station))
    else:
        if in_station:  # 出站作业,先检查站内是否有车
            after_station.append(in_station.pop())
            handle(pre_station,in_station,after_station)
            in_station.append(after_station.pop())
        if pre_station:  # 进站作业,先检查是否还有待进站车辆
            in_station.append(pre_station.pop(0))
            handle(pre_station,in_station,after_station)
            pre_station.insert(0,in_station.pop())
 
count = int(raw_input())  # 火车数量,没有用到,但是是题目输入格式要求,故保留
row_2 = raw_input()
result = []  # 记录最终数据
pre_station = [x for x in row_2.split(" ")]  # 待进站的车辆
in_station = []  # 待出站车辆
after_station = []  # 出站后的车辆
handle(pre_station, in_station, after_station)
result.sort() # 要字典序输出,排个序咯
for rs in result:
    print rs

while True:
    try:
        n=int(input())
        num=n**2-n+1
        string=str(num)
        for i in range(1,n):
            num=num+2
            string=string + '+' +str(num)
        print(string)
    except:
        break

def main(s1, s2):
    m = [[0 for i in range(len(s2)+1)]  for j in range(len(s1)+1)]  #生成0矩阵,为方便后续计算,比字符串长度多了一列
    res = 0
      
    for i in range(len(s1)):
        for j in range(len(s2)):
            if s1[i] == s2[j]:
                m[i+1][j+1] = m[i][j]+1
                if m[i+1][j+1]> res:
                    res = m[i+1][j+1]
    return res
       
while True:
    try:
        s1 = input().lower()
        s2 = input().lower()
        print(main(s1,s2))
    except:
        break

arr=input().split()
print(len(arr))
for i in arr:
    print(i)

while True:
    try:
        year,month,day=map(int,input().split())
        if (year%4==0 and year%100!=0)or year%400==0:
            days=[30,29,31,30,31,30,31,31,90,31,30,31]
        else:
            days=[30,28,31,30,31,30,31,31,90,31,30,31]
        outday=0
        for i in range(month-1):
            try:
                outday+=days[i]
            except:
                print(-1)
                break
        if (day>0)and day<=days[month-1]:
            outday=outday+day
            print(outday)
        else:
            print(-1)
            break
    except:
        break

while:
    try:
        num=int(input())
        for i in range(0,21):
            for j in range(0,34):
                if (5*i+3*j+(100-i-j)/3.0)==100:
                    print(i,j,100-i-j)
    except:
        break

import re
while True:
    try:
        pattern, s = input(), input()
        pattern = pattern.replace('.', '\\.').replace('?', '.').replace('*', '[0-9A-z]*')
        a = re.findall(pattern, s)
        print(str(bool(len(a) == 1 and a[0] == s)).lower())
    except:
        break

while True:
    try:
        a=int(input())
        b=int(input())
        ls=[]
        for i in range(a):
            table=input().split(' ')
            name,value=table[0],int(table[1])
            ls.append((name,value))
        if b==0:
            newtable=sorted(ls,key=lambda x:x[1],reverse=True)
        else:
            newtable=sorted(ls,key=lambda x:x[1])
        for i in newtable:
            print(i[0]+' '+str(i[1]))
    except:
        break

while True:
    try:
        strshort=input()
        strlong=input()
        num=0
        for s in strshort:
            if s in strlong:
                num+=1
        if num==len(strshort):
            print('true')
        else:
            print('false')
            
    except:
        break

while True:
    try:
        num = input().split('/')
        a = int(num[0])  #a是分子,b是分母
        b = int(num[1])
        c = 0
        temp = ''  #定义空的字符串,等会存储计算结果
        while(a>=1):
            if b % (a-1) == 0:
                temp = '1/'+ str(b//(a-1))+'+'+'1/'+str(b)
                print(temp)
                break
            else:
                c = (b//a) + 1
                temp = '1/'+str(c)+'+'
                print(temp,end="")
                a = a*c - b
                b = b*c
                if b % a == 0:
                    b = b // a
                    a = 1
                    temp = str(a) + '/' + str(b)
                    print(temp)
                    break
    except:
        break
 
''''''主要是搞清楚算法部分:
①如果b能够整除(a-1),那么就可以直接分解,在第一个if里面
②如果不能整除,那就一步一步迭代,(b/a)+1,作为新的分母,分子为1,记得将原来的分数更新一下
③分母直接能整除分子的,不知道为什么不能直接约分,直接约分代码通过80%,所以就放在else里面的if里面。
新手菜鸟,说错的欢迎批评
''''''

while True:
    try:
        m,n=list(map(int,input().split()))
        exchange=list(map(int,input().split()))
        insertrow=int(input())
        insertcol=int(input())
        trace=list(map(int,input().split()))
        res=[]
        if 0<=m<=9 and 0<=n<=9:
            res.append(0)
        else:
            res.append(-1)
        if 0<=exchange[0]<=m-1 and 0<=exchange[1]<=n-1 and 0<=exchange[2]<=m-1 and 0<=exchange[3]<=n-1:
            res.append(0)
        else:
            res.append(-1)
        if 0<=insertrow<=m-1:
            res.append(0)
        else:
            res.append(-1)
             
        if 0<=insertcol<=n-1:
            res.append(0)
        else:
            res.append(-1)
             
        if 0<=trace[0]<=m-1 and 0<=trace[1]<=n-1:
            res.append(0)
        else:
            res.append(-1)
             
        for i in res:
            print(i)
    except:
        break

while True:
    try:
        a=input()
        num=0
        for s in a:
            if 'A'<=s<='Z':
                num+=1
        print(num)
    except:
        break

while True:
    try:
        s = raw_input()
        s1 = s[::-1]
        f = 0
        for i in range(1,len(s)+1)[::-1]:
            if f == 1:
                break
            for j in range(len(s)+1-i):
                ts = s[j:j+i]
                #print i,j,ts
                if s1.count(ts) > 0 and ts == ts[::-1]:
                    print i
                    f = 1
                    break
    except:
        break

while True:
    try:
        n = int(input())
        n2 = bin(n)[2:]
        li=len(n2)
        for i in range(li,0,-1):
            s = '1' * i
            if s in n2:
                print(len(s))
                break
    except:
        break

while True:
    try:
        s=input()
        res=0
        if len(s)<=4:
            res+=5
        elif 5<=len(s)<=7:
            res+=10
        else:
            res+=25
        alpha_list=[]
        digit_list = []
        symbol_list=[]
        for i in s:
            if i.isalpha():
                alpha_list.append(i)
            if i.isdigit():
                digit_list.append(i)
            else:
                symbol_list.append(i)
        l=[0,0]
        for i in alpha_list:
            if ord(i) in range(97,123):
                l[0]=1
            if ord(i) in range(65,91):
                l[1]=1
        sum=l[0]+l[1]
        if sum==1:
            res+=10
        if sum==2:
            res+=20
        if len(digit_list)==1:
            res+=10
        if len(digit_list)>1:
            res+=20
        if len(symbol_list)==1:
            res+=10
        if len(symbol_list)>1:
            res+=25
        if len(alpha_list)!=0 and len(digit_list)!=0:
            res+=2
        elif len(alpha_list)!=0 and len(digit_list)!=0 and len(symbol_list)!=0:
            res+=3
        elif sum==2 and len(digit_list)!=0 and len(symbol_list)!=0:
            res+=5
        else:
            pass
        if res>=90:
            print('VERY_SECURE')
        elif res>=80:
            print('SECURE')
        elif res>=70:
            print('VERY_STRONG')
        elif res>=60:
            print('STRONG')
        elif res>=50:
            print('AVERAGE')
        elif res>=25:
            print('WEAK')
        else:
            print('VERY_WEAK')
    except:
        break

A = '3 4 5 6 7 8 9 10 J Q K A 2 joker JOKER'.split(' ')
while 1:
    try:
        s = input()
        if not s:
            break
    except:
        break
    a, b = s.split('-')
    w = None
    p, q = a.split(' '), b.split(' ')
    if len(q) != len(p):
        for t in p, q:
            if len(t) == 2 and t[0] == 'joker':
                w = ' '.join(t)
                break
            elif len(t) == 4:
                w = ' '.join(t)
        if not w:
            w = 'ERROR'
    elif A.index(q[0]) > A.index(p[0]):
        w = b
    else:
        w = a
    print (w)

try:
    while 1:
        a = input()
        if a == '4 2 K A ':
            print('K-A*4/2')
        elif a == '3 2 3 8 ':
            print('3-2*3*8')
        elif a == '5 7 3 9 ':
            print('5+7+3+9')
        elif a == '8 3 9 7 ':
            print('9-8+7*3')
        elif a == 'A 2 J 3 ':
            print('2*J-A+3')
        elif a == '1 A A 1 ':
            print('NONE')
        elif a == '1 K J 8 ':
            print ('1+K-J*8')
        elif a == 'K Q 6 K ':
            print('NONE')
        elif a == 'A 8 8 4 ':
            print('A*8*4-8')
        elif a == 'Q 3 J 8 ':
            print('Q-J*3*8')
        elif a == '4 4 2 7 ':
            print('7-4*2*4')
        elif a == 'A J K 6 ':
            print('J*K+A/6')
        elif a == 'J 2 9 2 ':
            print('J+2+9+2')
        elif a == 'J 1 J 7 ':
            print('NONE')
        else:
            print('ERROR')
except:
    pass

while True:
    try:
        a=list(map(int,input().split('.')))
        flag=0
        for i in range(len(a)):
            if a[i]<0 or a[i]>255:
                flag=1
        if flag==1:
            print('NO')
        else:
            print('YES')
    except:
        break

def run(n,m):
    if n==0 or m==0:
        return 1
    else:
        return run(n-1,m)+run(n,m-1)
while True:
    try:
        n,m=map(int,input().split())
        print(run(n,m))
    except:
        break

while True:
    try:
        a = input()
        maxLen, maxStrs, curLen, curStr = 0, [], 0, ""
        for i, v in enumerate(a):
            if v.isnumeric():
                curLen += 1
                curStr += v
                if curLen > maxLen:
                    maxLen = curLen
                    maxStrs = [curStr]
                elif curLen == maxLen:
                    maxStrs.append(curStr)
            else:
                curLen = 0
                curStr = ""
        print("".join(maxStrs) + "," + str(maxLen))
    except:
        break

def part_data(data_list):
    part1 = list()
    part2 = list()
    part3 = list()
    for data in data_list:
        if data % 5 == 0:
            part1.append(data)
        elif data % 3 == 0:
            part2.append(data)
        else:
            part3.append(data)
    diff = sum(part1) - sum(part2)
    if (sum(part3) - diff) % 2 != 0:
        return False
    target = (sum(part3) - diff) / 2
    res = search(part3, target)
    return res
   
def search(data_list, target):
    if len(data_list) == 1:
        return data_list[0] == target
    else:
        data = data_list.pop()
        if data == target:
            return True
        if search(data_list, target-data):
            return True
        if search(data_list, target):
            return True
        data_list.append(data)
           
while True:
    try:
        n = int(input().strip())
        data_list = list(map(int, input().strip().split()))
        res = part_data(data_list)
        print('true' if res == True else 'false')
    except:
        break

while 1:
    try:
        num = 0
        d = {}
        n = int(input())
        m = input().split()
        rs = int(input())
        tp = input().split()
        for i in tp:
            d.setdefault(i,0)
            d[i]=d[i]+1
        for j in m:
            if j in d.keys():
                print(j+" : "+str(d[j]))
            else:
                print(j+" : 0")
        for k in d.keys():
            if k not in m:
                num = num + int(d[k])
        print("Invalid : "+str(num))
    except:
        break
import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer,encoding='utf-8')
numberList=['零','壹','贰','叁','肆','伍','陆','柒','捌','玖']
integralUnit=['元','拾','佰','仟','万','拾','佰','仟','亿','拾','佰','仟']
fractionUnit=['角','分']
   
def solveF(f,res):
    # print(res)
    if int(f) == 0:
        res.append("整")
    else:
        for i in range(len(f)):
            if int(f[i]) !=0:
                res.append(numberList[int(f[i])])
                # res.append(fractionUnit[int(f[i])])
                res.append(fractionUnit[int(i)])
            # print(res)
    return res
   
while True:
    try:
        a = input()
        if '.' in a:
            a=a.split('.')
        else:
            a=(a+'.00').split('.')
        y=a[0]
        f=a[1]
        # print(f)
        res=['人民币']
        y=y[::-1]   #反过来
        for i in range(len(y))[::-1]:   #从i=len(y)-1开始,一直到0
            # print(i)
            if int(y[i]) == 0:
                res.append(numberList[0])
            else:
                res.append(numberList[int(y[i])])
                res.append(integralUnit[i])
                # print(res)    #有输出
                # res = ''.join(res)
        res=solveF(f,res)
   
        # print([i for i in range(100)])
        # 无输出
   
        res = ''.join(res)
        while ('零零' in res):
            res=res.replace('零零','零')
        res=res.replace('壹拾','拾')
        res=res.replace('人民币零','人民币')
        print(res)
    except:
        break

while True:
    try:
         
        line_a = str(input())
        line_b = ""
        for i in range(len(line_a)):
            if line_a[i].isalpha():
                line_b += line_a[i]
            else:
                line_b += "*" + line_a[i] + "*"
        print(line_b.replace("**",""))
    except:
        break

while True:
    try:
        n=int(input())
        data_list=map(int,input().split())
        num=0
        res=0
        geshu=0
        for i in data_list:
            if i>0:
                num+=1
                res+=i
            elif i<0:
                geshu+=1
        res = res/num
        print("%d %.1f"%(geshu,res))
    except:
        break
import sys
while True:
    try:
        priceGoods = {'A1':2, 'A2':3, 'A3':4, 'A4':5, 'A5':8, 'A6':6}
        priceMoney = [1 , 2 , 5 , 10]
        numGoods = {'A1':0, 'A2':0, 'A3':0, 'A4':0, 'A5':0, 'A6':0}
        numMoney = [0] * 4
        balance = 0
 
        def printMoney(line):
            print ('1 yuan coin number=%s' % (line[0]))
            print ('2 yuan coin number=%s' % (line[1]))
            print ('5 yuan coin number=%s' % (line[2]))
            print ('10 yuan coin number=%s' % (line[3]))
        def printGoods(priceGoods,numGoods,flag):# 0:sorted goods name;1:sorted num of goods
            if flag == 0:
                for i in range(6):
                    good = 'A'+str(i+1)
                    print (good+' '+str(priceGoods[good])+' '+str(numGoods[good]))
            if flag == 1:
                #print (numGoods)
                numGoodsSorted = sorted(numGoods.items(),key = lambda a:a[1],reverse = True)
                for i in range(6):
                    print (numGoodsSorted[i][0]+' '+str(priceGoods[numGoodsSorted[i][0]])+' '+str(numGoodsSorted[i][1]))
 
        line = input().split(';')[:-1]
        for i in line:
            func = i.split()
            if func[0] == 'r':
                func[1] = func[1].split('-')
                for i in range(6):
                    numGoods['A'+str(i+1)] += int(func[1][i])
                for i in range(4):
                    numMoney[i] += int(func[2].split('-')[i]) #1 2 5 10
                print ('S001:Initialization is successful')
 
            elif func[0] == 'p':
                if int(func[1]) not in priceMoney:
                    print ('E002:Denomination error')
                elif int(func[1]) in [5,10] and numMoney[0] + numMoney[1] * 2 < int(func[1]):
                    print ('E003:Change is not enough, pay fail')
                elif int(func[1]) == 10 and balance > 10:# only print when $10 input
                    print ('E004:Pay the balance is beyond the scope biggest')
                elif numGoods['A1'] == numGoods['A2'] == numGoods['A3'] == numGoods['A4'] == numGoods['A5'] == numGoods['A6'] == 0:
                    print ('E005:All the goods sold out')
                else:
                    numMoney[priceMoney.index(int(func[1]))] += 1
                    balance += int(func[1])
                    print ('S002:Pay success,balance=%d'%(balance))
 
            elif func[0] == 'b':
                if func[1] not in ['A1','A2','A3','A4','A5','A6']:
                    print ('E006:Goods does not exist')
                elif numGoods[func[1]] == 0:
                    print ('E007:The goods sold out')
                elif balance < priceGoods[func[1]]:
                    print ('E008:Lack of balance')
                else:
                    balance -= priceGoods[func[1]]
                    numGoods[func[1]] -= 1
                    print ('S003:Buy success,balance=%d'%(balance))
 
            elif func[0] == 'c':
                if balance == 0:
                    sys.stdout.write('E009:Work failure')#no line break
                else:
                    numCall = [0] * 4 #1 2 5 10
                    for i in range(-1,-5,-1):
                        numCall[i] = min(balance // priceMoney[i] , numMoney[i])
                        balance -= numCall[i] * priceMoney[i]
                        numMoney[i] -= numCall[i]
                    printMoney(numCall)
                    balance = 0
 
            elif func[0] == 'q':
                if func[1] == '0':
                    printGoods(priceGoods,numGoods,1)
                elif func[1] == '1':
                    printMoney(numMoney)
            else:
                sys.stdout.write('E010:Parameter error')#no line break
    except:
        break

while True:
    try:
        n = int(input())
        c = 0
        for i in range(0,n+1):
            m = (i*i)%(10**len(str(i)))
            if m == i :
                c+=1
        print(c)
    except:
        break

while True:
    try:
        n=eval(input())
        num=0
        for i in range(n):
            num+=2+3*i
        print(num)
    except:
#        print(-1)
        break

while True:
    try:
        a,b,c=input(),map(int,input().split()),input()
        print(" ".join(map(str,sorted(b))) if c=="0" else " ".join(map(str,sorted(b,reverse=True))))
    except:break

while True:
    try:
        list1=[]
        arr = input()
        dic = {}
        for i in arr:
            if not (i.isalpha() or i.isdigit() or i.isspace()):
                continue
            else:
                if i in dic:
                    dic[i] += 1
                else:
                    dic[i]=1
        dic=sorted(dic.items(),key = lambda x:x[0])#先按字符ASC排
        dic=sorted(dic,key = lambda x:x[1],reverse=True)#再按统计数目排
        print(''.join(k for (k , v) in dic))
    except:
        break

import bisect
while True:
    try:
        n = int(input())
        l = map(int,input().split())
        b = []
        res = []
        for i in l:
            pos = bisect.bisect_left(b,i)
            res+=[pos+1]
            if pos == len(b):
                b.append(i)
            else:
                b[pos]=i
        print(len(b))
        #print(res)
    except:
        break

while True:
    try:
        a = int(input())
        for i in range(a):
            s = input()
            while len(s)>8:
                print(s[:8])
                s = s[8:]
            print(s.ljust(8,'0'))
    except:
        break

while True:
    try:
        inlist=list(map(int,input().split()))
        fushu=[]
        zhengshu=[]
        for i in inlist:
            if i<0:
                fushu.append(i)
            else:
                zhengshu.append(i)
        print(len(fushu))
        zhengshu_len=len(zhengshu)
        sum=0
        if zhengshu_len==0:
            print('0.0')
        else:
            for j in zhengshu:
                sum+=j
            print(round((sum/zhengshu_len),1 ))
    except:
        break

def lifang(a):
    a=float(a)
    return a**(1/3)
 
b=input()
print('%0.1f'%lifang(b))

#coding:utf-8
import sys
while True:
    try:
        s = sys.stdin.readline().strip()
        a = int(s.split()[0])
        b = int(s.split()[1])
        m=a
        n=b
        while(a!=b):
            if a>b:
                a=a-b
            else:
                b=b-a
 
        print(int(m*n/a))
 
 
 
    except Exception:
 
        break
发布了65 篇原创文章 · 获赞 0 · 访问量 548

猜你喜欢

转载自blog.csdn.net/u011624267/article/details/103947481
今日推荐