알고리즘

3048-백준-개미

easysheep 2023. 3. 4. 00:38

1. 문제 출처

https://www.acmicpc.net/problem/3048

 

3048번: 개미

T초가 지난 후에 개미의 순서를 출력한다. 첫 번째 개미 그룹은 왼쪽에서 오른쪽으로 움직이고, 두 번째 그룹은 반대 방향으로 움직인다.

www.acmicpc.net

2. 풀이

단순 구현 문제이다.

l1,l2 = map(int,input().split())
N1 = list(input().rstrip())
N2 = list(input().rstrip())

t = int(input())


N1 = N1[::-1]
road = N1+N2

for _ in range(t):
    for i in range(len(road)-1):
        if road[i] in N1 and road[i+1] in N2:
            road[i],road[i+1] = road[i+1],road[i]
            if road[i+1] == N1[-1]:
                break
    
print("".join(road))