-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPython Question by HackerRank.py
More file actions
116 lines (107 loc) · 3.17 KB
/
Copy pathPython Question by HackerRank.py
File metadata and controls
116 lines (107 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
''' решение задач с HackerRank
'''
#TODO 2:
# CSS colors are defined using a hexadecimal (HEX) notation for the combination of Red, Green, and Blue color values (RGB).
# Specifications of HEX Color Code
#
# ■ It must start with a '#' symbol.
# ■ It can have 3 or 6 digits.
# ■ Each digit is in the range of 0 to F. (1,...,9,0,A,B,C,D,E and F).
# ■ A-F letters can be lower case. (a,b,c,d,e and f are also valid digits).
# Valid Hex Color Codes
# #FFF
# #025
# #F0A1FB
# Invalid Hex Color Codes
# #fffabg
# #abcf
# #12365erff
# You are given N lines of CSS code. Your task is to print all valid Hex Color Codes, in order of their occurrence from top to bottom.
# CSS Code Pattern
# Selector
# {
# Property: Value;
# }
# Input Format
# The first line contains N, the number of code lines.
# The next N lines contains CSS Codes.
# Constraints 0 < N < 50
# Output Format: Output the color codes with '#' symbols on separate lines.
# Sample Input
# 11
# #BED
# {
# color: #FfFdF8; background-color:#aef;
# font-size: 123px;
# background: -webkit-linear-gradient(top, #f9f9f9, #fff);
# }
# #Cab
# {
# background-color: #ABC;
# border: 2px dashed #fff;
# }
# Sample Output
# #FfFdF8
# #aef
# #f9f9f9
# #fff
# #ABC
# #fff
# ss_list=[
# '#BED',
# '{',
# ' color: #FfFdF8; background-color:#aef;',
# ' font-size: 123px;', '',
# '}',
# '#Cab',
# '{',
# ' background-color: #ABC;',
# ' border: 2px dashed #fff;',
# '}'
# ]
# sstr='#BED{ color: #FfFdF8; background-color:#aef; font-size: 123px;}#Cab{ background-color: #ABC; border: 2px dashed #fff;}'
signature_list = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f']
hex_list=[] # список для результата
# n = int(input())
n=11
ss=''
it=0
body_of_tag=0
for ss in ss_list:
step = 0
if ss.find('{') != -1:
body_of_tag=1
# print('Вошли в тело')
continue
if ss.find('}') != -1:
body_of_tag=0
# print('Вышли из тела')
continue
while body_of_tag:
it=ss.find('#',it,)
if it == -1:
it=0
break
it+=1
# print('begin find in ', ss[it::1])
new_num_str = '#'
for single in ss[it::1]:
if single.lower() in signature_list:
new_num_str+=single
# print('new_num_str=',new_num_str)
else: # закончился порядок цифр (0...9, A...F)
# print('end of find')
it += len(new_num_str) # пропускаем уже проверенную строку и дальше будем искать с нового места
step += len(new_num_str)
# print('it=', it, ' ss()=',ss[it::1])
# print('body_of_tag =', body_of_tag)
if len(new_num_str)==4 or len(new_num_str)==7:
hex_list.append(new_num_str)
# print('hex_list', hex_list)
new_num_str = ''
break
else:
new_num_str=''
break
for out in hex_list:
print(out)