Created
June 6, 2018 03:57
-
-
Save DonghoonPark12/064b8d63ccbd538ac820b4c1267c1563 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#1. 이름 분석 | |
''' | |
def chunk(long,n): | |
for i in range(0,len(long),n): | |
yield long[i:i+n] | |
f = open("input.txt","r") | |
long = f.read() #문자열로 읽음 | |
#print(long) | |
print(type(long)) | |
#print(len(long)) | |
#str1 = ''.join(long) #리스트를 String으로 | |
#print(len(str1)) | |
#print(long.count('박')+long.count('김')) # 5 : 1번문제, 잘못됬다. | |
names = long.split(',') #',' 단위로 구분 | |
#print(long.split(',')) #결과는 같은데... | |
print(type(names)) #결과는 같은데... | |
#print(long[1]) # 의 | |
#print(name.count('박')+name.count('김')) # 0 | |
#print(name[1]) #이재명 | |
# #chunk(str1,4) | |
# #print(len(str1)) | |
park = 0 | |
kim = 0 | |
for name in names: | |
if name.startswith('박'): | |
park += 1 | |
elif name.startswith('김'): | |
kim += 1 | |
print(park, kim) | |
print(names.count('이재수')) # 2 : 2번문제 | |
# set(long) | |
No_dupli = set(names) # 3번 문제, 집합은 표현이 [ ~~ ]가 된다. | |
No_dupli_list = list(No_dupli) # set to list, 표현이 { ~~~ }가 된다. | |
print(No_dupli_list) | |
#print(No_dupli_list.sort) # <built-in method sort of list object at 0x0000017FF233E348> | |
No_dupli_list.sort() # () 붙여줄 것!! | |
print(No_dupli_list) | |
# print(name - (name - No_dupli)) | |
# print(No_dupli.sort()) | |
''' | |
#2. 합의 제곱과 제곱의 합의 차 | |
''' | |
#print(range(101)) | |
sum = 0 | |
sum2 = 0 # 합의 제곱 | |
for i in range(1,101): | |
sum += i*i | |
sum2 += i | |
sum2 = sum2 ** 2 #합의 제곱 | |
print(sum) | |
print(sum2) | |
print(sum2 - sum) | |
''' | |
#3. 1부터 10까지 각 숫자의 갯수 | |
# list = [] | |
# for i in range(1,101): | |
# #''.join(i) | |
# list.append(i) #리스트의 원소를 문자열 처럼 한 열로 만들어서 1의 갯수, 0의 갯수 ~~~ 이렇게 구하려고 한다. | |
# | |
# #a = "".join(list) | |
# str_ = str(list) | |
# #print(str_) | |
# #str2 = str_.strip('[]') # 벗기다. | |
# str2 = str_[1:-1] # 벗기다 | |
# | |
# #print(str2) | |
# | |
# out = ''.join(map(str,list)) # list의 원소를 각각 str(함수)로 바꾼다 + 그리고 붙인다. ''(사이에 아무것도 없이) | |
# print(out) | |
# | |
# for i in range(0,10): | |
# print("'%d' : %d" % (i, out.count('%d' % i )) ) | |
''' | |
from collections import defaultdict | |
d = defaultdict(int) | |
for number in range(1, 100+1): | |
for c in str(number): | |
d[c] += 1 | |
print(dict(d)) | |
''' | |
#4 DashInsert | |
f = open("input.txt","r") | |
long = f.read() #문자열로 읽음 | |
#print(len(long)) | |
flag1 = 0 | |
flag2 = 0 | |
list = [] | |
for i in long: | |
list.append(i) | |
print(list) | |
backup = 0 | |
for i in list: | |
j=0 | |
if j !=0 and (int(i) % 2) ==0 and int(backup) % 2 == 0 : | |
list.insert(j, '*') | |
if j != 0 and (int(i) % 2) == 1 and int(backup) % 2 == 1: | |
list.insert(j, '-') | |
backup = i | |
j = j+1 | |
print(list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment