🛡️ 코딩테스트/🛡️ 코테 : 프로그래머스
C# 2016년 - 프로그래머스 [Lv.1]
맨텀
2023. 1. 22. 19:10
출처: 프로그래머스 코딩 테스트 연습
https://school.programmers.co.kr/learn/courses/30/lessons/12901
나의 풀이
using System;
public class Solution {
public string solution(int a, int b) {
string[] strArray = new string[7]{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
DateTime time = new DateTime(2016, a, b);
int index = (int)time.DayOfWeek;
return strArray[index];
}
}
다른사람풀이
using System;
public class Solution {
public string solution(int a, int b) {
string answer = "";
DateTime dt = new DateTime(2016,a,b);
answer = dt.ToString("ddd").ToUpper();
return answer;
}
}
DateTime 사용자 서식문자열을 활용함.
https://learn.microsoft.com/ko-kr/dotnet/standard/base-types/custom-date-and-time-format-strings
사용자 지정 날짜 및 시간 서식 문자열
사용자 지정 날짜 및 시간 서식 문자열을 사용하여 DateTime 또는 DateTimeOffset 값을 텍스트 표현으로 변환하거나 날짜 및 시간의 문자열을 구문 분석하는 방법을 알아봅니다.
learn.microsoft.com