달리기 경주 문제
내 코드
using System;
using System.Collections.Generic;
using System.Linq;
public class Solution {
public string[] solution(string[] players, string[] callings) {
List<string> answer = new List<string>();
Dictionary<string, int> resultDic = new Dictionary<string, int>();
List<string> list = new List<string>();
int num = 0;
foreach(string player in players)
{
resultDic.Add(player, num);
num++;
}
foreach(string call in callings)
{
int n = resultDic[call];
string name = players[n - 1];
players[resultDic[call]-1] = call;
//추월당한 사람 이름
//var _key = resultDic.FirstOrDefault(x => x.Value == resultDic[call] - 1).Key;
players[resultDic[call]] = name;
resultDic[name]++; //추월 당한 사람 순위 ++
resultDic[call]--; //추월 하려는 사람 순위 --
}
return players;
}
}
728x90
'코딩테스트_c# > 프로그래머스' 카테고리의 다른 글
프로그래머스 ) 연습문제 - 덧칠하기 Level.1_C# (0) | 2024.02.14 |
---|---|
프로그래머스 ) 연습문제 - 바탕화면 정리 Level.1 _C# (0) | 2024.02.14 |
프로그래머스 ) 코딩테스트 입문 - 겹치는 선분의 길이 Level.0_C# (0) | 2024.02.14 |
프로그래머스 ) 코딩테스트 입문 - 평행_C# (0) | 2024.02.14 |
프로그래머스 ) 코딩테스트 입문 - 옹알이 (1)_C# (0) | 2024.02.14 |