이코테_구현

  • 상하좌우
import numpy as np
lst_ = [list(input().split()) for _ in range(2)]
5
R R R U D D
n = int(lst_[0][0])
maps =   [[1 for i in range(1,n+1)] for _ in range(1,n+1)]
des = {"R" : [0,1], "L" : [0, -1], "U" : [-1,0], "D" : [1, 0] }
start = [0,0]
for i in lst_[1]:
    if (np.array(start)[0] + np.array(des[i])[0] < 0) or (np.array(start)[1] + np.array(des[i])[1] < 0) :
        pass
    else:
        start = np.array(start) + np.array(des[i])
print("{} {}".format(start[0]+1, start[1]+1)) 
print(f"{start[0]+1} {start[1]+1}")
3 4
  • 예시 답안
n = int(input())
5
x, y = 1, 1
plans = input().split()
R R R U D D
plans
['R', 'R', 'R', 'U', 'D', 'D']
dx = [0, 0, -1, 1]
dy = [-1, 1, 0 , 0]
move_types = ['L', 'R', 'U', 'D']
for plan in plans:
    for i in range(len(move_types)):
        if plan == move_types[i]:
            nx = x + dx[i]
            ny = y + dy[i]
    if nx<1 or ny<1 or nx>n or ny>n:
        continue
    x,y = nx, ny
print(x,y)
3 4
  • 시각
n = int(input())
5
count= 0
for i in range(n+1):
    for j in range(60):
        for k in range(60):
            if '3' in str(k) or '3' in str(i) or '3' in str(j):
                count+=1
                
        
            
count
11475
  • 예시답안
h = int(input())

count = 0 

for i in range(h+1):
    for j in range(60):
        for k in range(60):
            if '3' in str(i) + str(j) + str(k):
                count+=1
print(count)
5
11475
  • 왕실의 나이트
p = input()
c2
dx = [2, 2, -2, -2, 1, -1, 1, -1]
dy = [1, -1, 1 , -1, 2, 2, -2, -2]
s = {"a" : 1, "b":2, "c" :3, "d":4,"e":5, "f": 6, "g" :7, "h" : 8}
x , y =  s[p[0]]-1, int(p[1])-1
count = 0
for i in range(8):
    nx = x + dx[i]
    ny = y + dy[i]
    if nx>=0 and ny>=0 and nx<=7 and ny+7:
        count+=1
print(count)
6
  • 예시답안
input_data = input()
row = int(input_data[1])
column = int(ord(input_data[0])) - int(ord('a')) + 1

steps = [(-2,-1), (-1,-2), (1, -2), (2, -1), (2, 1), (1, 2), (-1, 2), (-2, 1)]

result = 0
for step in steps:
    next_row = row + step[0]
    next_column = column + step[1]
    if next_row>=1 and next_row <=8 and next_column >=1 and next_column <=8:
        result+=1
print(result)
a1
2
  • 게임 개발
n, m = map(int,input().split())
4 4
x, y, z = map(int, input().split())
1 1 0
maps =  [list(map(int, input().split())) for _ in range(n)]
1 1 1 1
1 0 0 1
1 1 0 1
1 1 1 1
maps
[[1, 1, 1, 1], [1, 0, 0, 1], [1, 1, 0, 1], [1, 1, 1, 1]]
destination = [(-1,0), (0, 1), (1, 0), (0, -1)]
x, y, z = map(int, input().split())
1 1 0
visited = [[x,y]]
count = 1
while True:
    if x-1>=0 and y-1>=0 and x+1<n and y+1<m:
        if ((maps[x-1][y] == 1) or ([x-1, y] in visited)) and ((maps[x+1][y] == 1) or ([x+1, y] in visited)) and  ((maps[x][y+1] == 1) or ([x, y+1] in visited)) and  ((maps[x][y-1] == 1) or ([x, y-1] in visited)):
            x+= destination[z-2][0]
            y+= destination[z-2][1]
            if maps[x][y] == 1:
                break
        else:
            for i in range(1,5):
                if x-1>=0 and y-1>=0 and x+1<n and y+1<m:
                    if maps[x+ destination[z-i][0]][y + destination[z-i][1]] == 0:
                    
                        if [x+destination[z-i][0],y+destination[z-i][1]] not in visited:
                            x+= destination[z-i][0]
                            y+= destination[z-i][1]
                            visited.append([x,y])                        
                            z = destination.index(destination[z-i])
                            count+=1
                            break
                        else: 
                            pass


count
3
  • 예시 답안
n, m = map(int, input().split())

d = [[0]*m for _ in range(n)]
x, y, direction = map(int, input().split())
d[x][y] = 1

array = []
for i in range(n):
    array.append(list(map(int, input().split())))

dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

def turn_left():
    global direction
    direction -=1
    if direction == -1:
        direction = 3

count = 1
turn_time = 0
while True:
    turn_left()
    nx = x + dx[direction]
    ny = y + dy[direction]
    if d[nx][ny] == 0 and array[nx][ny] == 0:
        d[nx][ny] = 1
        x = nx
        y = ny
        count +=1
        turn_time = 0
        continue
    else:
        turn_time +=1
    if turn_time ==4:
        nx = x - dx[direction]
        ny = y - dy[direction]
        if array[nx][ny] == 0:
            x = nx
            y = ny
        else:
            break
        turn_time = 0
print(count)
4 4
1 1 0
1 1 1 1
1 0 0 1
1 1 0 1
1 1 1 1
3

*

* 

* 

* 

* 

* 

* 

* 




Comments