Contents
1. ë¬¸ì œí’€ì�´ 첫번째 ë¬¸ì œ ¶
í� ..우리집 ì�¸í„°ë„·ì�´ ê°‘ìž�기 먹통ë�˜ëŠ” 바람ì—� 지금ì—�서야 올리네;;
�...-_-;;
ì±…ì—�서 숫ìž�를 ê°€ì§€ê³ ìž¥ë‚œ 친경우는 없는것 같아서...
�...-_-;;
ì±…ì—�서 숫ìž�를 ê°€ì§€ê³ ìž¥ë‚œ 친경우는 없는것 같아서...
1.1. 최대값, 최소값 ¶
1. ìž…ë ¥ 3가지수를 받아서 if문ì�„ ì�´ìš©í•˜ì—¬ 최대값 최소값ì�„ ì¶œë ¥í•˜ëŠ” 프로그램ì�„ 작성하세요. DeleteMe)스펙ì�´ if문ì�˜ 언급ì�€ 잘못ë�œê²ƒ 아닌가요?
2. 1 ì�„ 활용하여 10ê°œì�˜ ìž…ë ¥ì¤‘ì—� 가장 최대, 최소 ê°’ì�„ì�„ ì¶œë ¥í•˜ëŠ” 프로그램ì�„ 작성하세요.
2. 1 ì�„ 활용하여 10ê°œì�˜ ìž…ë ¥ì¤‘ì—� 가장 최대, 최소 ê°’ì�„ì�„ ì¶œë ¥í•˜ëŠ” 프로그램ì�„ 작성하세요.
1.2.1.1. Normal Method ¶
~cpp print 'problem 1-1' print 'type 3 values' v1 = input() v2 = input() v3 = input() print 'max=',max(v1, v2, v3) print 'min=',min(v1, v2, v3) print 'problem 1-2' print 'type 10 values ' vv1 = input() vv2 = input() vv3 = input() vv4 = input() vv5 = input() vv6 = input() vv7 = input() vv8 = input() vv9 = input() vv10 = input() print 'max=',max(vv1,vv2,vv3,vv4,vv5,vv6,vv7,vv8,vv9,vv10) print 'min=',min(vv1,vv2,vv3,vv4,vv5,vv6,vv7,vv8,vv9,vv10)
ref와 같� input� eval � 받는거니까. 가능하게 �는 것. 그래서 �게 가능해집니다. --아무개
~cpp input( [prompt]) Equivalent to eval(raw_input(prompt)). Warning: This function is not safe from user errors! It expects a valid Python expression as input; if the input is not syntactically valid, a SyntaxError will be raised. Other exceptions may be raised if there is an error during evaluation. (On the other hand, sometimes this is exactly what you need when writing a quick script for expert use.) If the readline module was loaded, then input() will use it to provide elaborate line editing and history features. Consider using the raw_input() function for general input from users.
~cpp >>> input() 1+2 3
1.2.1.2. Using Recursion ¶
~cpp
def myproc(count,mx,mn):
val = int(raw_input())
if count != 0 :
if mx == None :
return myproc(count-1, val, val)
else :
return myproc(count-1, max(mx, val),min(mn,val))
else :
return max(mx,val),min(mn,val)
print 'problem 1-1'
max1,min1=myproc(2,None,None)
print 'max=',max1,'min=',min1
print 'problem 1-2'
max2,min2=myproc(9,None,None)
print 'max=',max2,'min=',min2
1.2.1.3. Using Iteration ¶
~cpp
def iterproc(count):
mx=None
mn=None
for i in range(0,count):
val = int(raw_input())
if mx == None:
mx = val
mn = val
else :
mx = max(mx,val)
mn = min(mn,val)
return mx,mn
print 'problem 1-1'
max1,min1=iterproc(3)
print 'max=',max1,'min=',min1
print 'problem 1-2'
max2,min2=iterproc(10)
print 'max=',max2,'min=',min2
1.2.2.1.1. Using List Comprehension ¶
~cpp
def printMaxMin(cnt):
inputList = [ input() for i in range(cnt) ]
print 'max=%d, min=%d'%(max(inputList),min(inputList))
print 'problem 1-1'
printMaxMin(3)
print 'problem 1-2'
printMaxMin(10)
1.2.2.1.2. Using map ¶
~cpp
def printMinMax(cnt):
inputList = map(lambda x:input(),range(cnt))
print 'max=%d, min=%d'%(max(inputList),min(inputList))
print 'problem 1-1'
printMinMax(3)
print 'problem 1-2'
printMinMax(10)
1.2.2.2. Using Generator for input ¶
~cpp
def inputNum(v=[]):
while True:
v.append(input())
yield max(v),min(v)
maxMin=()
print 'problem 1-1'
inputNum_gen=inputNum()
for i in range(3):
maxMin=(inputNum_gen.next())
print 'max=%d, min=%d'%maxMin
inputNum_gen=inputNum()
print 'problem 1-2'
for i in range(10):
maxMin=(inputNum_gen.next())
print 'max=%d, min=%d'%maxMin
1.3.2. í’€ì�´ 예 ¶
~cpp
inNums = [ int(i) for i in raw_input('input numbers with space:\n').split() ]
print 'max=%d min=%d' % (max(inNums),min(inNums))
1.3.3. ìž„ì�¸íƒ� ¶
~cpp
a = raw_input()
news = []
for i in a.split():
news.append(int(i))
print max(news), min(news)
- ì œê°€ ì•„ëŠ”ì„ (문법)ì—�ì„ ì�´ë°©ë²•ì�´ 가장 간단한듯; - ìž„ì�¸íƒ�
ì�´ëŸ° 경우를 ê°œì„ í•˜ê¸° 위해서 map 함수가 있는것입니다. ì�´ë¥¼ Haskellì—�서 차용해와 문법ì—� ë‚´ìž¥ì‹œí‚¤ê³ ìžˆëŠ” 것ì�´ List Comprehension ì�´ê³ 차후 Genrator Expression으로 확장ë� ì˜ˆì •ìž…ë‹ˆë‹¤. ê·¸ë¦¬ê³ print 와 ,혼용ì�€ 그리 추천하지 않습니다. print를 여러번 호출하는것과 ë�™ì�¼í•œ 효과ë�¼ì„œ, 좋ì�€ 컴퓨터ì—�서ë�„ 눈ì—� 뜨ì�¼ë§Œí�¼ 처리 ì†�ë�„ê°€ 늦습니다. --NeoCoin
~cpp a = raw_input() news = map(lambda x:int(x), a.split()) print max(news), min(news)











.png)