在一行上输入两个长度
,仅由小写字母
、大写字母
、数字
构成的字符串
和
,代表待处理的字符串。
在一行上输出一个字符串,代表最终的字符串。
dec fab
5D37BF
在这个样例中,第一步合并后得到
;第二步,排序得到
;随后,按位转换为十进制数,并执行“调整”操作:
对于第一个字符
,其十进制数为
,二进制数为
,翻转后得到
,再转换回十六进制数为
;
对于第二个字符
,翻转后得到
;
对于第三个字符
,翻转后得到
;
对于第四个字符
,翻转后得到
;
对于第五个字符
,翻转后得到
;
对于第六个字符
,翻转后得到
。
ab CD
3B5D
在这个样例中,第一步合并后得到
;第二步,排序得到
。需要特别注意的是,这里的排序是按照
码表的顺序进行排序的。
123 15
88C4A
s = input() s = s.replace(" ", "") # combine and sort two string l1 = [s[i] for i in range(len(s)) if i%2==0] l2 = [s[i] for i in range(len(s)) if i%2==1] l1.sort() l2.sort() def encrypt(c): # convert to binary c = bin(int(c, 16))[2:].rjust(4, "0")[::-1] # convert binary to hex c = hex(int(c, 2))[2:].upper() return c # construct a hashmap hmap = {str(k):encrypt(str(k)) for k in range(10)} for i in "ABCDEFabcdef": hmap[i] = encrypt(i) # convert character in string if necessary for i in range(len(l1)): if l1[i] in hmap: l1[i] = hmap[l1[i]] for i in range(len(l2)): if l2[i] in hmap: l2[i] = hmap[l2[i]] res = '' # generate result for i in range(len(s)): if i%2 == 0: res += l1.pop(0) else: res += l2.pop(0) print(res)
s=list("".join(input().split())) s[0::2]=sorted(s[0::2]) s[1::2]=sorted(s[1::2]) for i in s: try: i=int(i,16) i=bin(i)[2:].rjust(4,"0")[::-1] i=int(i,2) i=hex(i)[2:] if i.islower(): i=i.upper() print(i,end="") except: print(i,end="")
def reserve(str: str): return str[-1::-1] def str2Hex2Bin2SortedHexStr(s: str): decimalism = int(s, 16) binary = bin(decimalism)[2:] if len(binary) < 4: binary = (4 - len(binary)) * "0" + binary binary = reserve(binary) hexStr = hex(int(binary, 2))[2:] if hexStr.isalpha(): return hexStr.upper() else: return hexStr def step1(str1: str, str2: str): return str1 + str2 def step2(mergeStr: str): strLength = len(mergeStr) evenIndexStr = [] oddIndexStr = [] for i in range(strLength): if i%2 != 0: # odd digit index oddIndexStr.append(mergeStr[i]) else: # even digit index evenIndexStr.append(mergeStr[i]) evenIndexStr = sorted(evenIndexStr) oddIndexStr = sorted(oddIndexStr) res = "" for i in range(len(evenIndexStr)): res += evenIndexStr[i] try: res += oddIndexStr[i] except Exception as e: # print(e) pass return res def step3(sortedStr: str): str1 = "ABCDEF" str2 = "abcdef" res = "" strList = list(sortedStr) for i in range(len(strList)): if (strList[i] in str1)&nbs***bsp;(strList[i] in str2)&nbs***bsp;(strList[i].isdigit()): if strList[i].isalpha(): strList[i] = strList[i].lower() res += str2Hex2Bin2SortedHexStr(strList[i]) else: res += strList[i] return res str1, str2 = map(str, input().strip().split(" ")) print(step3(step2(step1(str1, str2))))
#冲冲冲
s0, s1 = input().split() # 转换一 s = s0 + s1 # 转换二 ji, ou = [], [] for i in range(len(s)): if i % 2 == 0: ou.append(s[i]) else: ji.append(s[i]) ji.sort() ou.sort() tmp = 0 s = '' while ji and ou: if tmp == 0: s += ou[0] ou = ou[1:] tmp = 1 elif tmp == 1: s += ji[0] ji = ji[1:] tmp = 0 if ji: s += ji[0] else: s += ou[0] # 转换三 res = '' for c in s: if '0' <= c <= '9'&nbs***bsp;'A' <= c <= 'F'&nbs***bsp;'a' <= c <= 'f': F2A = int(c, 16) A2B = format(F2A, '04b') tA2B = A2B[::-1] tB2A = int(tA2B, 2) tA2F = hex(tB2A)[2:] res += tA2F.upper() else: res += c print(res)
from itertools import zip_longest def encod(char: str): if char.isdigit()&nbs***bsp;ord('A') <= ord(char) <= ord('F')&nbs***bsp;ord('a') <= ord(char) <= ord('f'): return hex(int(bin(int(char,base=16))[2:][::-1].ljust(4,'0'),base=2))[-1].upper() return char def process(s1, s2): s = s1 + s2 s_even = sorted(s[::2]) s_odd = sorted(s[1::2]) s_new = ''.join(map(lambda x: ''.join([x[0],x[1]]),zip_longest(s_even,s_odd,fillvalue=''))) return ''.join(map(encod,s_new)) s = input().split(' ') print(process(s[0],s[1]))
# 初学者按照题意一步一步做的,可能没有答案写的好,请参考。 a=''.join(input().split()) l1,l2=[],[] for i in range(0,len(a),2): l1.append(a[i]) l1=sorted(l1) for i in range(1,len(a),2): l2.append(a[i]) l1=sorted(l1) l2=sorted(l2) index1,index2=0,0 s='' for i in range(len(a)): if (i+2)%2==0: s+=l1[index1] index1+=1 else: s+=l2[index2] index2+=1 m,q='','' for one in s: if one.isalpha(): if 'A'<=one<='F'or'a'<=one<='f': m+=hex(int(('0b'+bin(int(one,16)).replace('0b','')[::-1]),2)).replace('0x','').upper() else: m+=one elif one.isdigit(): q=bin(int(one)).replace('0b','') q=int(((4-len(q))*'0'+q)[::-1],2) if q>=10: m+=hex(q).replace('0x','').upper() else: m+=str(q) print(m) '''下面是调试用的代码''' # m='f' # print(m,type(m)) # q=hex(int(('0b'+bin(int(m,16)).replace('0b','')[::-1]),2)).replace('0x','') # # q=bin(int(m,16)) # print(q,type(q)) # m='5' # q=bin(int(m)).replace('0b','') # q=int(((4-len(q))*'0'+q)[::-1],2) # if q>=10: # q=hex(q).replace('0x','').upper() # else: # q=str(q) # print(q,type(q))