信息社会,有海量的数据需要分析处理,比如公安局分析身份证号码、 QQ 用户、手机号码、银行帐号等信息及活动记录。
信息社会,有海量的数据需要分析处理,比如公安局分析身份证号码、 QQ 用户、手机号码、银行帐号等信息及活动记录。
一组输入整数序列I和一组规则整数序列R,I和R序列的第一个整数为序列的个数(个数不包含第一个整数);整数范围为0~(2^31)-1,序列个数不限
从R依次中取出R<i>,对I进行处理,找到满足条件的I
: I
整数对应的数字需要连续包含R<i>对应的数字。比如R<i>为23,I 为231,那么I 包含了R<i>,条件满足 。 按R<i>从小到大的顺序:
(1)先输出R<i>;
(2)再输出满足条件的I
的个数; (3)然后输出满足条件的I
在I序列中的位置索引(从0开始); (4)最后再输出I
。 附加条件:
(1)R<i>需要从小到大排序。相同的R<i>只需要输出索引小的以及满足条件的I
,索引大的需要过滤掉 (2)如果没有满足条件的I
,对应的R<i>不用输出 (3)最后需要在输出序列的第一个整数位置记录后续整数序列的个数(不包含“个数”本身)
序列I:15,123,456,786,453,46,7,5,3,665,453456,745,456,786,453,123(第一个15表明后续有15个整数)
序列R:5,6,3,6,3,0(第一个5表明后续有5个整数)
输出:30, 3,6,0,123,3,453,7,3,9,453456,13,453,14,123,6,7,1,456,2,786,4,46,8,665,9,453456,11,456,12,786
说明:
30----后续有30个整数
3----从小到大排序,第一个R<i>为0,但没有满足条件的I
,不输出0,而下一个R<i>是3 6--- 存在6个包含3的I
0--- 123所在的原序号为0
123--- 123包含3,满足条件
15 123 456 786 453 46 7 5 3 665 453456 745 456 786 453 123 5 6 3 6 3 0
30 3 6 0 123 3 453 7 3 9 453456 13 453 14 123 6 7 1 456 2 786 4 46 8 665 9 453456 11 456 12 786
将序列R:5,6,3,6,3,0(第一个5表明后续有5个整数)排序去重后,可得0,3,6。 序列I没有包含0的元素。 序列I中包含3的元素有:I[0]的值为123、I[3]的值为453、I[7]的值为3、I[9]的值为453456、I[13]的值为453、I[14]的值为123。 序列I中包含6的元素有:I[1]的值为456、I[2]的值为786、I[4]的值为46、I[8]的值为665、I[9]的值为453456、I[11]的值为456、I[12]的值为786。 最后按题目要求的格式进行输出即可。
a = input().split()[1:] s = ' '.join(a) #要按照从小到大排列 b = list(map(int, input().split()))[1:] b = sorted(set(b)) inclu = [str(i) for i in b if str(i) in s] dic ={} res_lst = [] for i in inclu: dic[i]=0 sub_lst = [] for j in range(len(a)): if i in a[j]: sub_lst.append(str(j)) sub_lst.append(a[j]) dic[i] += 1 res_lst.append(sub_lst) fnl ='' for i in range(len(res_lst)): key = inclu[i] fnl += key+' '+str(dic[key])+' ' fnl += ' '.join(res_lst[i])+' ' result = (str(len(fnl.split())) +' '+ fnl).split() print(' '.join(result))
a=input().split() b=input().split() N=a[0] c=[] for i in set(b[1:]): c.append(int(i)) M=len(c) c=sorted(c) path=[] for i in range(M): stuck=[] for j in range(1,int(N)+1): if str(c[i]) in a[j]: stuck.extend([j-1,int(a[j])]) if len(stuck)>0: path.append(c[i]) path.append(int(len(stuck)/2)) path.extend(stuck) if len(path)>0: ans=[len(path)] ans.extend(path) for i in ans: print(i,end=' ')
I = input() I = I[I.index(" ") + 1:] Is = I.split(" ") R = input() Rs = R[R.index(" ") + 1:].split(" ") Rdict= dict() Is_len = len(Is) nums = list() # store number order in nums for key in Rs: if not Rdict.get(key): Rdict[key] = [] nums.append(int(key)) # loop through Is to check if value pairs for i in range(Is_len): if key in Is[i]: Rdict[key].append(str(i)) Rdict[key].append(Is[i]) nums.sort() count = 0 res = "" for num in nums: num_len = len(Rdict[str(num)]) if num_len == 0: continue else: # current count means the count of value pairs cur_count = int(num_len / 2) res += str(num) + " " + str(cur_count) + " " + " ".join(Rdict[str(num)]) + " " count += 2 + num_len res = str(count) + " " + res print(res)
i = input().split(' ')[1:] r = sorted(list(set(input().split(' ')[1:])),key=lambda x:int(x)) d = {x:['',0] for x in r} for index in range(len(i)): for value in r: if value in i[index]: d[value][1] += 1 d[value][0] += ' ' + str(index) + ' ' + i[index] fin_str = '' count = 0 for index in r: if d[index][1] != 0: count += (d[index][1]+1) * 2 fin_str += ' ' + index + ' ' + str(d[index][1]) + d[index][0] print(str(count)+fin_str)
# 感觉我的方法简单点 R = input().split(' ')[1:] I = list(map(int,input().split(' ')))[1:] I = list(set(I)) I.sort() data = [] for i in I: l = [] for j in range(len(R)): if str(i) in R[j]: l.extend([str(j),R[j]]) if len(l)>0: data.extend([str(i),str(int(len(l)/2))]) data.extend(l) data.insert(0,str(len(data))) print(' '.join(data))
arr_i = input().split()[1:] arr_r = map(int,input().split()[1:]) arr_r = sorted(list(set(arr_r))) arr_r = list(map(str,arr_r)) res = [] for i in arr_r: tmp = [i] for j, ele in enumerate(arr_i): if i in ele: tmp.extend([str(j),ele]) num = len(tmp)//2 if num: tmp.insert(1,str(num)) res.extend(tmp) res.insert(0,str(len(res))) print(' '.join(res))
def print_list(seq_I,seq_R): # seq_I [123,456,786,453,46,7,5,3,665,453456,745,456,786,453,123] # seq_R [0,3,6] R_list = [] for i in seq_R: seq_i_tishen = [] for xx in seq_I: seq_i_tishen.append(xx) num_contain = 0#用来存储第二个数字 例为6 R_manzu = []# 用来暂时存储 例['123', '453', '3', '453456', '453', '123'] R_manzuindex = []# 例子 [0, 3, 7, 9, 13, 14] for j in seq_i_tishen: if str(i) in j: R_manzu.append(j) R_manzuindex.append(seq_i_tishen.index(j)) seq_i_tishen[seq_i_tishen.index(j)] = '*' num_contain += 1 if R_manzu != []: R_list.append(i) R_list.append(num_contain) # print(R_list) for n in range(len(R_manzu)): R_list.append(int(R_manzuindex[n])) R_list.append(int(R_manzu[n])) print(len(R_list),end=' ') for abc in R_list: print(abc,end=' ') return 0 while True: try: I_seq = input().split()[1:] R_seq = list(map(int,input().split()[1:])) R_seq = list(set(R_seq)) R_seq.sort() print_list(I_seq,R_seq) except: break
line1 = input().split() line2 = input().split() I = line1[1:] R = sorted(line2[1:]) # R.sort() sort_R = list(map(int, R)) sort_R1 = [] for i in range(len(sort_R)): if not sort_R[i] in sort_R[(i+1):]: sort_R1.append(sort_R[i]) RI = {} for i in range(len(sort_R1)): Ri = [] for j in range(len(I)): if str(sort_R1[i]) in I[j] and I[j] not in Ri: Ri.append(j) RI[sort_R1[i]] = Ri # print(sorted(RI)) Re = [] Ie = list(map(int, I)) # print(I) for a in sorted(RI.keys()): if RI[a] != []: Re.append(int(a)) Re.append(len(RI[a])) for j in range(len(RI[a])): Re.append(int(RI[a][j])) Re.append(int(I[int(RI[a][j])])) print(len(Re), end=' ') for i in range(len(Re)): print(Re[i], end=' ')
target = input().split(" ")[1:] nums = sorted(list(map(int, input().split(" ")))[1:]) dic = {} for num in nums: s = str(num) if s in dic: continue dic[s] = [] for i, tar in enumerate(target): if s in tar: dic[s].append((i, tar)) ans = [] for s, t in dic.items(): if not t: continue ans.append(s) ans.append(str(len(t))) for x, y in t: ans.append(str(x)) ans.append(str(y)) print(str(len(ans)), " ".join(ans))纯模拟,妥妥shabi
while True: try: a, b = input().split(), input().split() numI, numR = int(a[0]), int(b[0]) I, R = a[1:], b[1:] ele, rec, total = [], [{}], 0 res = '' R = sorted(list(set(R)), key=lambda x: int(x)) # 整数字符排序 for i in range(len(R)): for j in range(numI): if R[i] in I[j]: rec[-1][j] = I[j] if rec[-1]: ele.append(R[i]) rec.append({}) for i in range(len(ele)): res += ' ' + ele[i] + ' ' + str(len(rec[i])) total += 2 for k, v in rec[i].items(): total += 2 res += ' ' + str(k) + ' ' + v print(total, end = '') print(res) except: break
while True: try: l = input().split(' ')[1:] r = list(map(int, input().split(' ')[1:])) r.sort() r_sort = [] for i in r: if i not in r_sort: r_sort.append(i) r_sort = list(map(str, r_sort)) dic = {} for i in r_sort: dic[i] = [] for i in r_sort: for j in range(len(l)): if i in l[j]: dic[i].append((j, l[j])) else: continue key_record = [] total_number = 0 for key, value in dic.items(): if value == []: continue else: key_record.append(key) total_number += 2 total_number = total_number + len(value)*2 result = [total_number] for key, value in dic.items(): if value == []: continue else: result.append(key) result.append(len(value)) for pair in value: result.append(pair[0]) result.append(pair[1]) result = [str(i) for i in result] print(' '.join(result)) except: break
def r_get( s1_follow): s1_empty = [] for x in s1_follow: if x not in s1_empty: s1_empty.append(x) return sorted(s1_empty) def i_get(s0, s1_follow): s0_top, s0_follow = s0[0], s0[1:] s0_ok_list = [] for s1 in map(str, s1_follow): if len( [x for x in s0_follow if s1 in x] ): s0_ok = [f'{index} {x}' for index, x in enumerate(s0_follow) if s1 in x] s0_ok_list.append( f"{s1} {len(s0_ok)} {' '.join( s0_ok )}" ) return ' '.join( s0_ok_list ) while True: try: s0, s1 = input().split(), input().split() s1_top, s1_follow = s1[0], map(int, s1[1:]) s1_follow = r_get(s1_follow) s0_ok_list = i_get(s0, s1_follow) print(len(s0_ok_list.split()), s0_ok_list) except: break
I=input().split()[1:] R=input().split()[1:] R=sorted(list(set(R)),key=int) opt=[] for i in range(len(R)): line=[R[i]] for j in range(len(I)): if R[i] in I[j]: line.append(j) line.append(I[j]) if len(line)>1: line.insert(1, len(line)//2) opt+=line opt=[len(opt)]+opt print(*opt,sep=' ')
""" 解题分析: 1、先对R进行去重和排序 2、判断I的的元素是否包含R,包含则记录满足条件的I,R和I的索引 3、要输出元素的个数,满足条件的R(升序) 4、满足条件的I的个数 5、I所在的索引(去最小的那个),I的元素 """ I = list(input().split()) R = list(input().split()) # 从第二个元素开始取,第一个元素表示个数,并使用set去重 R_set = set(R[1:]) # 进行降序排序,要转化成int a_list = list(R_set) b_list = list(map(int, a_list)) new_R = sorted(b_list, reverse=False) # 创建列表存放符合要求的R元素 # 创建字典存放符合要求的I的索引:I的值 r_list = [] r_dict = {} # 判断 I是否包含R,满足条件的存入R for r in new_R: i_dict = {} for i in range(1,len(I)): if str(r) in str(I[i]): # 过滤重复的元素 if r not in r_list: r_list.append(r) i_dict[i] = I[i] r_dict[str(r)] = i_dict # 把符合要求的R进行排序 o_list = sorted(r_list, reverse=False) # 把要输出的内容存放到列表中,第一个元素使用0占位,后续赋值要输出的长度 last_list = [0] for one in o_list: # 把符合要求的R存入指定的列表 last_list.append(one) last_list.append(len(r_dict[str(one)])) # 根据符合要求的R,取出对应字典中的数据,即符合要求的I new_dict = r_dict[str(one)] for j in new_dict.keys(): # 遍历字典把数据同一存放在列表中 last_list.append(j-1) last_list.append(new_dict[j]) # 计算列表长度-占位的 long_num = len(last_list)-1 last_list[0] = long_num for l in last_list: print(l, end=' ')这个问题没有python 3的相关解答,就把注释写的比较仔细了