Computer Science/Jongol (정올)

[Jongol] 기초다지기 : 배열1

꿈꾸는어린이 2018. 2. 3. 19:53

//

일시 : 2018.02.03

장소 : 답십리 도서관

내용 : 정올 기초다지기 배열1, 파이썬 2버전

//

555

  num = raw_input()
str_list = num.split()

str = ""
for i in range(0, 10):
str += str_list[i]
print(str)

556

  
str_list = list(range(1, 11))

for i in range(0, 10):
print(str_list[i]),

★★ range 의 기능 활용하여 특정 범위의 숫자 리스트에 넣기

  • 리스트 = list(range(횟수))

  • 리스트 = list(range(시작, 끝))

  • 리스트 = list(range(시작, 끝, 증가폭))

557

  
str = raw_input()
str_list = str.split()

print("%s %s %s" % (str_list[0], str_list[3], str_list[6]))

558

  
num = raw_input()
num_list = num.split()

i = 0
while True:
if int(num_list[i]) == 0:
break
i += 1

for j in range(i-1, -1, -1):
print("%d" % int(num_list[j])),

559

  
class_score = [85.6, 79.5, 83.1, 80.0, 78.2, 75.0]

a, b = raw_input().split()

sum = class_score[int(a)-1] + class_score[int(b)-1]

print("%.1f" % sum)

560

  
num = raw_input()
num_list = num.split()

min = 1000

for i in range(0, len(num_list)):
if int(num_list[i]) < min:
min = int(num_list[i])

print("%d" % min)

561

  
num = raw_input()
num_list = num.split()

max = 0
min = 10000

for i in range(0, len(num_list)):
if int(num_list[i]) < 100:
if int(num_list[i]) > max:
max = int(num_list[i])
else:
if int(num_list[i]) < min:
min = int(num_list[i])

if max == 0:
max = 100
if min == 10000:
min = 100

print("%d %d" % (max, min))

562

  
num = raw_input()
num_list = num.split()

even_sum, odd_sum = 0, 0

for i in range(0, len(num_list), 2):
odd_sum += int(num_list[i])

for j in range(1, len(num_list), 2):
even_sum += int(num_list[j])

avg = float(odd_sum) / 5

print("sum : %d" % even_sum)
print("avg : %.1f" % avg)

★★563

  • 문자열을 정수형으로 바꾸었을 때와 안바꾸었을 때 정렬 결과 비교

  
#version1
num = raw_input()
num_list = num.split()

for i in range(len(num_list)):
num_list[i] = int(num_list[i])

print(num_list)

num_list.sort()
print(num_list)

num_list.reverse()
print(num_list)



##version2
num = raw_input()
num_list = num.split()

print(num_list)

num_list.sort()
print(num_list)

num_list.reverse()
print(num_list)




  
num = raw_input()
num_list = num.split()

for i in range(len(num_list)):
num_list[i] = int(num_list[i])

num_list.sort()
num_list.reverse()

for i in range(len(num_list)):
print("%d" % num_list[i]),

150

  
str = raw_input()
str_list = str.split()

for i in range(len(str_list)-1, -1, -1):
print("%s" % str_list[i]),

151

  
num = raw_input()
num_list = num.split()

sum = 0

for i in range(0, len(num_list), 2):
sum += int(num_list[i])

print("%d" % sum)

152

  
num = raw_input()
num_list = num.split()

odd, even = 0, 0

for i in range(0, len(num_list), 2):
odd += int(num_list[i])

for i in range(1, len(num_list), 2):
even += int(num_list[i])

print("odd : %d" % odd)
print("even : %d" % even)

153

  
num = raw_input()
num_list = num.split()

i = 0
while True:
if int(num_list[i]) == -1:
break
i += 1

if i <= 2 :
for j in range(0, i):
print("%s" % num_list[j]),
else:
for j in range(i-3, i):
print("%s" % num_list[j]),

154

  
num = raw_input()
num_list = num.split()

sum = 0
for i in range(0, len(num_list)):
sum += float(num_list[i])

avg = sum / len(num_list)
print("%.1f" % avg)

155

  
str_list = ['J', 'U', 'N', 'G', 'O', 'L']

input_str = raw_input()
i = 0

while True :
if i >= len(str_list):
print("none")
break

if input_str == str_list[i]:
flag = 1
print("%d" % i)
break
i += 1

156

  
num = raw_input()
num_list = num.split()

i = 0
min = 999
max = 0

while int(num_list[i]) != 999:
if int(num_list[i]) < min:
min = int(num_list[i])
if int(num_list[i]) > max:
max = int(num_list[i])
i += 1

print("max : %d" % max)
print("min : %d" % min)

157

  
num = raw_input()
num_list = num.split()

i = 0
cnt = 0
sum = 0

while int(num_list[i]) != 0:
if int(num_list[i]) % 5 == 0:
cnt += 1
sum += int(num_list[i])
i += 1

print("Multiples of 5 : %d" % cnt)
print("sum : %d" % sum)
print("avg : %.1f" % (float(sum)/cnt))

158

  
num = raw_input()
num_list = num.split()

new_list = []

i = 0

while int(num_list[i]) != 0:

if (int(num_list[i]) % 2) != 0:
new_list.append(int(num_list[i])*2)
elif (int(num_list[i]) % 2) == 0:
new_list.append(int(num_list[i])//2)
i += 1

print("%d" % i)

for i in range(0, len(new_list)):
print("%d" % new_list[i]),

159

  
num = int(raw_input())
score = raw_input().split()

for i in range(num):
score[i] = int(score[i])

score.sort()
score.reverse()

for i in range(num):
print("%d" % int(score[i]))