Code&Data Insights

BaekJoon Algorithm - Stage 7 [ 5-10 ] ( Python 3 ) 본문

Algorithm/BaekJoon Online Judge

BaekJoon Algorithm - Stage 7 [ 5-10 ] ( Python 3 )

paka_corn 2022. 1. 18. 06:55

 

 

2022.01.17

 

 

 

# 문자열 - stage 7

 

[2908]

[my code]

 

a,b = map(str,input().split())

a_new = int(a[2]+a[1]+a[0])

b_new = int(b[2]+b[1]+b[0])

if a_new > b_new:
    print(a_new)
else:
    print(b_new)

 

 

--> if else 대신 list/ join/ reversed 를 써서

max 함수로 풀수있음 

 

 

**  [::-1] 를 쓰면 문자열을 reverse 시킬 수 있음! 

 

[new code]

 

a,b = input().split()

a = a[::-1]

b = b[::-1]

if a > b:
    print(a)
else:
    print(b)

 

 

 

 

----------------------------

 

 

 

[5622]

[my code]

 

dial = input()
dial_count = 0

for i in dial:
    if i in "ABC":
        dial_count += 3
    elif i in "DEF":
        dial_count += 4
    elif i in "GHI":
        dial_count += 5
    elif i in "JKL":
        dial_count += 6
    elif i in "MNO":
        dial_count += 7
    elif i in "PQRS":
        dial_count += 8
    elif i in "TUV":
        dial_count += 9
    else:
        dial_count += 10
        
print(dial_count)

        

--> if 문 안쓰고 더 간단하게 만드는법? 

 

dial list를 만들수 있음

 

 

 

 

 

-------------------------

 

 

[1152]

[my code]

 

w = list(input().split())

print(len(w))

 

 

 

------------------------

 

 

 

[1157] , [2941],[1316] - 다시 풀어볼 것 ! ***** 

 

What is for _ in range in Python?
1. Use In Interpreter. Python automatically stores the value of the last expression in the interpreter to a particular variable called "_." You can also assign these value to another variable if you want
 
 
 
 
 
 

 

 

 

 

Comments