题解 | 东北林业大学第12届ACM校赛(低年级组)
奇妙的字符串
https://ac.nowcoder.com/acm/contest/45/A
[toc]
试题地址
https://ac.nowcoder.com/acm/contest/45
A
a=input()
b=input()
print(a[::-1]+b[::-1])
E
f=[0 for _ in range(105)]
f[1]=1
f[2]=1
for n in range(3,101,1):
f[n]=(6*f[n-1]+8*f[n-2])%9
while True:
try:
n=int(input())
print(f[n])
except Exception as e:
break
F
while True:
try:
a=list(input().split())
ret=sum(list(map(int,a)))%9
if(ret==0):
ret=9
print(ret)
except Exception as e:
break
G
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
b=Counter(a)
print(f'{b[1]:d} {b[5]:d} {b[10]:d}')
H
class Solution:
def init0(self,s):#预处理s
r = "#".join(s)
r = list(r)
r.append("#")
r.insert(0,"#")
return r
def manacher(self,s):
mx = -1
id0 = -1
max_length = -1
rIndex = -1
s = self.init0(s)
p =[-1 for i in range(len(s))]
# print(s)
for i in range(1,len(s)-1):
if i < mx:
p[i] = min(mx-i,p[2*id0-i])
else:
p[i] = 1
while i >= p[i] and i+p[i]<len(p) and s[i-p[i]] == s[i+p[i]]:
p[i] += 1
if mx < i + p[i]:
mx = i + p[i]
id0 = i
if p[i]-1 > max_length:
rIndex = i
max_length = p[i]-1
tmp = s[rIndex-p[rIndex]+1:rIndex+p[rIndex]]
return "".join("".join(tmp).split("#"))
while True:
try:
s = Solution()
ans=s.manacher(input())
print(len(ans))
except Exception as e:
break
I
t=int(input())
while t:
t=t-1
a=input()
if(a==a[::-1]):
print("yes")
else:
print("no")
J
from fractions import Fraction
t=int(input())
while t:
t=t-1
a=list(map(int,input().split()))
if (a[0]==1):
f1 =Fraction(a[1],a[2])
f2 =Fraction(a[3],a[4])
f=f1+f2
else:
f1 =Fraction(a[1],a[2])
f2 =Fraction(a[3],a[4])
f=f1-f2
if(f.denominator==1):
print(f'{f.numerator:d}/{f.denominator:d}')
else:
print(f)