洛谷 题单 官方精选 字符串 Python实现

P5733 【深基6.例1】自动修正

n=input()
print(n.upper())

P1914 小书童——凯撒密码

n=int(input())
s=input().rstrip()
x=""
for i in s:
    y=chr((ord(i)-97+n)%26+97)
    x+=y
print(x)

P1125 [NOIP2008 提高组] 笨小猴

from math import sqrt
def hanshu(n):
    m=int(sqrt(n))+1
    for i in range(2,m):
        if n%i==0:
            return False
    return True
n=input()
di={}
for i in n:
    if i not in di:
        di[i]=1
    else:
        di[i]+=1
a,b=min(di.values()),max(di.values())
c=b-a
if c==0 or c==1:
    print("No Answer")
    print("0")
else:
    if hanshu(c)==False:
        print("No Answer")
        print(0)
    else:
        print("Lucky Word")
        print(c)

P1957 口算练习题

n=int(input())
def hanshu1(x,y,z):
    if x=="a":
        return int(y)+int(z)
    elif x=="b":
        return int(y)-int(z)
    else:
        return int(y)*int(z)
def hanshu(x):
    if x=="a":
        return "+"
    elif x=="b":
        return "-"
    else:
        return "*"
for i in range(n):
    ls=[i for i in input().split()]
    if i==0:
        x=ls.pop(0)
        y=hanshu1(x,ls[0],ls[1])
        z=""
        z+=ls[0]+hanshu(x)+ls[1]+"="+str(y)
        print(z)
        print(len(z))
    else:
        if len(ls)==2:
            y=hanshu1(x,ls[0],ls[1])
            z=""
            z+=ls[0]+hanshu(x)+ls[1]+"="+str(y)
            print(z)
            print(len(z))
        else:
            x=ls.pop(0)
            y=hanshu1(x,ls[0],ls[1])
            z=""
            z+=ls[0]+hanshu(x)+ls[1]+"="+str(y)
            print(z)
            print(len(z))

P5015 [NOIP2018 普及组] 标题统计

ls=[chr(i) for i in range(65,91)]+[chr(i) for i in range(97,123)]+[str(i) for i in range(10)]
s=input().rstrip()
cnt=0
for i in s:
    if i in ls:
        cnt+=1
print(cnt)

P5734 【深基6.例6】文字处理软件

n=int(input().rstrip())
s=input().rstrip()
def hanshu1(x):
    global s
    s+=x
    print(s)
def hanshu2(x,y):
    global s
    s=s[x:x+y]
    print(s)
def hanshu3(x,y):
    global s
    a,b=s[:x],s[x:]
    z=""
    z+=a+y+b
    s=z
    print(s)
def hanshu4(x):
    global s
    a,b=len(s),len(x)
    for i in range(a-b+1):
        if x==s[i:i+b]:
            print(i)
            break
    else:
        print(-1)
for i in range(n):
    ls=[i for i in input().rstrip().split()]
    a=ls.pop(0)
    if a=="1":
        hanshu1(ls[0])
    elif a=="2":
        x,y=int(ls[0]),int(ls[1])
        hanshu2(x,y)
    elif a=="3":
        x,y=int(ls[0]),ls[1]
        hanshu3(x,y)
    else:
        hanshu4(ls[0])

P1308 [NOIP2011 普及组] 统计单词数

s=input()
S=input()
ls=[i for i in S.split()]
x=0
for i in ls:
    if i.lower()==s.lower():
        x+=1
y=len(S)
z=""
a=None
for i in range(y):
    if S[i]==" ":
        if z==s.lower():
            a=i
            break
        z=""
    else:
        z+=S[i].lower()
if a==None:
    print(-1)
else:
    print(x,a-len(s))

P1765 手机

ls=[chr(i) for i in range(97,123)]
di={}
for i in range(18):
    if i%3==0:
        di[ls[i]]=1
    elif i%3==1:
        di[ls[i]]=2
    elif i%3==2:
        di[ls[i]]=3
di["s"]=4
di["t"]=1
di["u"]=2
di["v"]=3
di["w"]=1
di["x"]=2
di["y"]=3
di["z"]=4
di[" "]=1
x=input()[:-1]
y=0
for i in x:
    y+=di[i]
print(y)

P3741 honoka的键盘

n=int(input())
s=input().rstrip()
x=s.count("VK")
for i in range(n):
    if s[i]=="V":
        S=s[:i]+"K"+s[i+1:]
        y=S.count("VK")
        if y>x:
            x=y
    else:
        S=s[:i]+"V"+s[i+1:]
        y=S.count("VK")
        if y>x:
            x=y
print(x)

P1321 单词覆盖还原

n=input()
m=len(n)
x,y=0,0
for i in range(m):
    if n[i]==".":
        continue
    else:
        if n[i]=="b":
            x+=1
        elif n[i]=="o":
            if n[i-1]=="b":
                continue
            else:
                x+=1
        elif n[i]=="y":
            if n[i-1]=="o":
                continue
            else:
                x+=1
        elif n[i]=="g":
            y+=1
        elif n[i]=="i":
            if n[i-1]=="g":
                continue
            else:
                y+=1
        elif n[i]=="r":
            if n[i-1]=="i":
                continue
            else:
                y+=1
        elif n[i]=="l":
            if n[i-1]=="r":
                continue
            else:
                y+=1
print(x)
print(y)

P1553 数字反转(升级版)

n=input()
if "." not in n and "%" not in n and "/" not in n:
    n=n[::-1]
    m=""
    x=True
    for i in n:
        if x==True and i=="0":
            pass
        else:
            x=False
            m+=i
    if m=="":
        m+="0"
    print(m)
elif "." in n:
    m=len(n)
    x=""
    for i in range(m):
        if n[i]==".":
            break
    a,b=n[:i],n[i+1:]
    a=a[::-1]
    b=b[::-1]
    y=True
    for i in a:
        if y==True and i=="0":
            pass
        else:
            y=False
            x+=i
    if x=="":
        x+="0"
    x+="."
    y=True
    for i in b:
        if y==True and i=="0":
            pass
        else:
            y=False
            x+=i
    if x[-1]==".":
        x+="0"
    while True:
        if x[-1]=="0":
            x=x[:-1]
        else:
            break
    if x[-1]==".":
        x+="0"
    print(x)
elif "/" in n:
    m=len(n)
    x=""
    for i in range(m):
        if n[i]=="/":
            break
    a,b=n[:i],n[i+1:]
    a=a[::-1]
    b=b[::-1]
    y=True
    for i in a:
        if y==True and i=="0":
            pass
        else:
            y=False
            x+=i
    if x=="":
        x+="0"
    x+="/"
    y=True
    for i in b:
        if y==True and i=="0":
            pass
        else:
            y=False
            x+=i
    if x[-1]=="/":
        x+="0"
    print(x)
else:
    n=n[:-1][::-1]
    m=""
    x=True
    for i in n:
        if x==True and i=="0":
            pass
        else:
            x=False
            m+=i
    if m=="":
        m+="0"
    m+="%"
    print(m)

P1603 斯诺登的密码

di={"one":1,"two":2,"three":3,"four":4,"five":5,"six":6,"seven":7,"eight":8,"nine":9,"ten":10,
"eleven":11,"twelve":12,"thirteen":13,"fourteen":14,"fifteen":15,"sixteen":16,"seventeen":17,"eighteen":18,
"nineteen":19,"twenty":20,"a":1,"both":2,"another":1,"first":1,"second":2,"third":3}
ls=[i.lower() for i in input().split()]
sl=[]
for i in ls:
    if i not in di:
        pass
    else:
        sl.append(pow(di[i],2,100))
sl.sort()
x=""
for i in sl:
    j=str(i)
    if len(j)==1:
        x+="0"+j
    else:
        x+=j
if x=="":
    print(0)
else:
    while True:
        if x[0]=="0":
            x=x[1:]
        else:
            break
    print(x)

P1200 [USACO1.1]你的飞碟在这儿Your Ride Is Here

n=input().rstrip()
m=input().rstrip()
di=dict(zip([chr(i) for i in range(65,91)],[i for i in range(1,27)]))
a=1
for i in n:
    a*=di[i]
b=1
for i in m:
    b*=di[i]
if a%47==b%47:
    print("GO")
else:
    print("STAY")

P1597 语句解析

n=input().strip()
m=len(n)
di={"a":0,"b":0,"c":0}
for i in range(m):
    if n[i]==":":
        x,y=n[i-1],n[i+2]
        try:
            y=eval(y)
        except:
            pass
        if type(y)!=str:
            di[x]=y
        else:
            di[x]=di[y]
for i in di.values():
    print(i,end=" ")

P1598 垂直柱状图

ls1=[i for i in input()]
ls2=[i for i in input()]
ls3=[i for i in input()]
ls4=[i for i in input()]
ls=ls1+ls2+ls3+ls4
m=[ls.count(chr(i)) for i in range(65,91)]
n=[chr(i) for i in range(65,91)]
di=dict(zip(n,m))
x=max(di.values())
a=x
for i in range(x):
    y=[]
    for j in n:
        if di[j]<a-i:
            y.append(" ")
        else:
            y.append("*")
    print(" ".join(y))
print(" ".join(n))
  • 4
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值