d={
"abc":2,
"def":3,
"ghi":4,
"jkl":5,
"mno":6,
"pqrs":7,
"tuv":8,
"wxyz":9,
}
while True:
try:
a,res=input(),""
for i in a:
if i.isupper():
if i!="Z":
res+=chr(ord(i.lower())+1)
else:
res+="a"
elif i.islower():
for j in d.keys():
if i in j:
res+=str(d[j])
break
else:
res+=i
print(res)
except:
break
while True:
try:
a=int(input())
if a!=0:
print(a//2)
except:
break
from collections import defaultdict
while True:
try:
a,df=input(),defaultdict(int)
for i in a:
df[i]+=1
for i in df:
if df[i]==min(df.values()):
df=df.replace(i,'')
print(df)
except:
break
def get_index(nums,target):
low,high=0,len(nums)-1
pos=len(nums)
while low<high:
mid=(low+high)//2
if nums[mid]<target:
low=mid+1
else:
high=mid
pos=mid
return pos
def increase_lis(l,res):
n=len(l)
temp=[10**10]*n
temp[0]=l[0]
res+=[1]
for i in range(1,n):
pos=get_index(temp,l[i])
res+=[pos+1]
temp[pos]=l[i]
return res
while True:
try:
n=int(input())
a=list(map(int,input().strip().split()))
dp_1,dp_2=[],[]
dp_1=increase_lis(a,dp_1)
new_list=a[::-1]
dp_2=increase_lis(new_list,dp_2)
maxValue=max([dp_1[i]+dp_2[n-i-1] for i in range(n)])
print(n-maxValue+1)
except:
break
while True:
try:
a=input().split()[1:]
b=map(str,sorted(map(int,set(input().split()[1:]))))
totalNum=0
res=""
for num in b:
singleRes,count="",0
for i,v in enumerate(a):
if num in v:
singleRes+=str(i)+" "+v+" "
totalNum+=2
count+=1
if count:
singleRes=num+" "+str(count)+" "+singleRes
totalNum+=2
res+=singleRes
print((str(totalNum)+" "+res).rstrip())
except:
break
while True:
try:
a = input()
# res是最终返回的字符串的列表形式,char是提取的英文字母。
res, char = [False] * len(a), []
# 经过这个循环,把相应的非英文字母及其位置存储到了res中。并且把英文字母提取出来了。
for i, v in enumerate(a):
if v.isalpha():
char.append(v)
else:
res[i] = v
# 使用lambda表达式排序,暴力有效。
char.sort(key=lambda c: c.lower())
# 将char中对应的字符填到res中。
for i, v in enumerate(res):
if not v:
res[i] = char[0]
char.pop(0)
print("".join(res))
except:
break
from collections import defaultdict
while True:
try:
dd = defaultdict(list)
a = input().split()
# words是输入的单词,lookup是要查找的单词,num是要查找兄弟单词的索引,brothers是找到的兄弟单词列表
words, lookup, num, brothers = a[1:1 + int(a[0])], a[-2], int(a[-1]), []
for i in words:
dd["".join(sorted(i))].append(i)
for i in dd["".join(sorted(lookup))]:
if i != lookup: brothers.append(i)
# 下面这两行坑的老子调了半个小时。
print(len(brothers))
if brothers and num <= len(brothers):
print(sorted(brothers)[num - 1])
except:
break
def issu(x):
tem = 2
while tem**2<=x:
if x%tem==0:
return False
tem+=1
return True
def find(a,l1,l2,l3):
for i in range(0,len(l3)):
if issu(a+l3[i]) and l1[i]==0:
l1[i]=1
if l2[i]==0 or find(l2[i],l1,l2,l3):
l2[i] = a
return True
return False
try:
while True:
n = input()
n = int(n)
l = list(map(int,input().split()))
ji,ou = [],[]
for i in range(n):
if l[i]%2==0:
ou.append(l[i])
else:
ji.append(l[i])
result = 0
match = [0]*len(ou)
for i in range(0,len(ji)):
used = [0]*len(ou)
if find(ji[i],used,match,ou):
result+=1
print(result)
except:
pass
while True:
try:
a, b = input(), input()
resA, resB = "", ""
for i in a:
if i.isupper():
if i != "Z":
resA += chr(ord(i) + 1).lower()
else:
resA += "a"
elif i.islower():
if i != "z":
resA += chr(ord(i) + 1).upper()
else:
resA += "A"
elif i.isdigit():
if i != "9":
resA += chr(ord(i) + 1)
else:
resA += "0"
for i in b:
if i.isupper():
if i != "A":
resB += chr(ord(i) - 1).lower()
else:
resB += "z"
elif i.islower():
if i != "a":
resB += chr(ord(i) - 1).upper()
else:
resB += "Z"
elif i.isdigit():
if i != "0":
resB += chr(ord(i) - 1)
else:
resB += "9"
print(resA)
print(resB)
except:
break
while True:
try:
dic = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
s = input().replace(" ", "") #s是输入的合并后的字符串
ss = "" #ss为最终返回的字符串
odd, even = "", "" # 字符串的奇数子串和偶数子串
# 经过下面的循环,提取奇数与偶数的子串。
for i, v in enumerate(s):
if i % 2 == 0:
even += v
else:
odd += v
# 奇数与偶数部分排序
odd = "".join(sorted(odd))
even = "".join(sorted(even))
# 如果字符串在0123456789abcdefABCDEF范围内,对其做变换,否则不做任何处理。
for i in range(len(even)):
if even[i] in "0123456789abcdefABCDEF":
ss += dic[int(bin(dic.index(even[i].upper())).replace("0b", "").rjust(4, "0")[::-1], 2)]
else:
ss += even[i]
if len(odd) != i: #注意偶数串可能比奇数串长一个字符,所以要做一下判断。
if odd[i] in "0123456789abcdefABCDEF":
ss += dic[int(bin(dic.index(odd[i].upper())).replace("0b", "").rjust(4, "0")[::-1], 2)]
else:
ss += odd[i]
print(ss)
except:
break
while True:
try:
dic = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
s = input().replace(" ", "") #s是输入的合并后的字符串
ss = "" #ss为最终返回的字符串
odd, even = "", "" # 字符串的奇数子串和偶数子串
# 经过下面的循环,提取奇数与偶数的子串。
for i, v in enumerate(s):
if i % 2 == 0:
even += v
else:
odd += v
# 奇数与偶数部分排序
odd = "".join(sorted(odd))
even = "".join(sorted(even))
# 如果字符串在0123456789abcdefABCDEF范围内,对其做变换,否则不做任何处理。
for i in range(len(even)):
if even[i] in "0123456789abcdefABCDEF":
ss += dic[int(bin(dic.index(even[i].upper())).replace("0b", "").rjust(4, "0")[::-1], 2)]
else:
ss += even[i]
if len(odd) != i: #注意偶数串可能比奇数串长一个字符,所以要做一下判断。
if odd[i] in "0123456789abcdefABCDEF":
ss += dic[int(bin(dic.index(odd[i].upper())).replace("0b", "").rjust(4, "0")[::-1], 2)]
else:
ss += odd[i]
print(ss)
except:
break
while True:
try:
dic = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]
s = input().replace(" ", "") #s是输入的合并后的字符串
ss = "" #ss为最终返回的字符串
odd, even = "", "" # 字符串的奇数子串和偶数子串
# 经过下面的循环,提取奇数与偶数的子串。
for i, v in enumerate(s):
if i % 2 == 0:
even += v
else:
odd += v
# 奇数与偶数部分排序
odd = "".join(sorted(odd))
even = "".join(sorted(even))
# 如果字符串在0123456789abcdefABCDEF范围内,对其做变换,否则不做任何处理。
for i in range(len(even)):
if even[i] in "0123456789abcdefABCDEF":
ss += dic[int(bin(dic.index(even[i].upper())).replace("0b", "").rjust(4, "0")[::-1], 2)]
else:
ss += even[i]
if len(odd) != i: #注意偶数串可能比奇数串长一个字符,所以要做一下判断。
if odd[i] in "0123456789abcdefABCDEF":
ss += dic[int(bin(dic.index(odd[i].upper())).replace("0b", "").rjust(4, "0")[::-1], 2)]
else:
ss += odd[i]
print(ss)
except:
break
while True:
try:
print(int(''.join(map(lambda n:bin(int(n)).replace('0b','').rjust(8,'0'),input().split('.'))),2))
adrbin=bin(int(input())).replace('0b','').rjust(32,'0')
print('.'.join(map(lambda n:str(int(n,2)),[adrbin[i*8:(i+1)*8]for i in range(4)])))
except:
break
while True:
try:
n, curNum = int(input()), 1
res = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
for j in range(i + 1):
res[i - j][j] = curNum
curNum += 1
for i in res:
print(" ".join(map(str, (filter(lambda i: i != 0, i)))))
except:
break
while True:
try:
n,num=int(input()),1
res=[[0 for i in range(n)] for j in range(n)]
for i in range(n):
for j in range(i+1):
res[i-j][j]=num
num+=1
for i in res:
print(" ".join(map(str,(filter(lambda i :i!=0,i)))))
while True:
try:
#key,string分别代表输入的key的加要密的字符串
#chars是密钥对应的字母表,res是要返回的结果。
key, string, chars, res = input(), input(), [], ""
#经过下面的循环,chars前面几个是密匙的字母
for i in key:
if i not in chars:
chars.append(i)
#如果输入的key中有小写字母,转为大写字母。
chars = list(map(lambda c: c.upper(), chars))
#剩下的字母,填充到chars里面。
for i in range(65, 91):
if chr(i) not in chars:
chars.append(chr(i))
# 将输入加密。
for i in string:
if i.isupper():
res += chars[ord(i) - 65]
elif i.islower():
res += chars[ord(i) - 97].lower()
else:
res += i
print(res)
except:
break
while True:
try:
a=int(input())-1
arr=[1,2]
while len(arr)<a:
arr.append(arr[-1]+arr[-2])
print(arr[-1])
except:
break
while True:
try:
a=int(input())-1
arr=[1,2]
while len(arr)<a:
arr.append(arr[-1]+arr[-2])
print(arr[-1])
except:
break
###This is a copy of Orli有异议 ####
import sys
def checkTwoKeys(twoKeys,a,result):
count = 0
index = 0
for y in twoKeys:
if a[0]==y.split()[0][:len(a[0])] and a[1]==y.split()[1][:len(a[1])]:
count += 1
index = twoKeys.index(y)
if count > 1 or count == 0:
print("unkown command")
elif count == 1:
print(result[index])
oneKey = 'reset'
twoKeys = ['reset board','reboot backplane','backplane abort','board add','board delete']
result = ['board fault','impossible','install first','where to add','no board at all']
for i in sys.stdin:
a = i.strip().split()
l = len(a)
if l <= 0 or l>=3:
print("unkown command")
elif l == 1:
if a[0] == oneKey[:len(a[0])]:
print("reset what")
else:
print("unkown command")
elif l == 2:
checkTwoKeys(twoKeys,a,result)
def trans(num,x):
total = 0
if len(x) == 1:
if abs(num-x[0]) < 0.001:
return 1
else:
return 0
else:
for i in range(len(x)):
a = x[i]
b = x[:]
b.pop(i)
total += trans(num-a, b) + trans(num+a, b) + trans(num*a, b) + trans(num/a, b)
return total
while True:
try:
nums = raw_input().strip().split()
num = [float(i) for i in nums]
total = trans(24.0,num)
if total == 0:
print 'false'
else:
print 'true'
except:
break
while True:
try:
def comp(x, y):
if x[1] > y[1]:
return 1
elif x[1] < y[1]:
return -1
else:
return 0
n = input()
law = input()
info_lis = []
for i in xrange(n):
info_lis.append(raw_input().split())
for i in xrange(n):
info_lis[i][1] = int(info_lis[i][1])
if law == 0:
info_lis.sort(comp, reverse=True)
if law == 1:
info_lis.sort(comp)
for i in xrange(n):
info_lis[i][1] = str(info_lis[i][1])
# print info_lis[i][0] + ' ' + info_lis[i][1]
print(' '.join(info_lis[i]))
except:
break
while True:
try:
string1=raw_input()
string2=raw_input()
l1=len(string1)
l2=len(string2)
dp=[[False]*(l2+1) for _ in range(l1+1)]
dp[0][0]=True
if string1[0]=='*':
dp[1][0]=True
for i in range(1,l1+1):
for j in range(1,l2+1):
if string1[i-1]=='*':
dp[i][j]=dp[i][j-1] or dp[i-1][j]
elif string1[i-1]=='?':
dp[i][j]=dp[i-1][j-1]
else:
dp[i][j]=dp[i-1][j-1] and string1[i-1]==string2[j-1]
if dp[l1][l2]==True:
print 'true'
else:
print 'false'
except:
break