글
프로그래머스 C# 2016년(int형 배열 생성, Datetime, JAVA)
public class Solution {
public string solution(int a, int b) {
string answer = "";
int[] month = new int[13] {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int days = b;
//31 29 31 30 31 30 31 31 30 31 30 31
for(int i=0;i<a;i++)
{
days += month[i];
}
if(days%7 == 1)
{
answer = "FRI";
}
else if(days%7 == 2)
{
answer = "SAT";
}
else if(days%7 == 3)
{
answer = "SUN";
}
else if(days%7 == 4)
{
answer = "MON";
}
else if(days%7 == 5)
{
answer = "TUE";
}
else if(days%7 == 6)
{
answer = "WED";
}
else if(days%7 == 0)
{
answer = "THU";
}
return answer;
}
}
//////
using System;
public class Solution {
public string solution(int a, int b) {
string answer = "";
DateTime dateValue = new DateTime(2016,a,b);
answer = dateValue.DayOfWeek.ToString().Substring(0,3).ToUpper();
return answer;
}
}
using System;
public class Solution {
public string solution(int a, int b) {
string answer = "";
string[] dayOfTheWeek = new string[7]{"SUN","MON","TUE","WED","THU","FRI","SAT"};
int[] daysOfMonth = new int[12]{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int totalDays = 5; //1월 1일이 금요일 이라서 초기화를 5로 시킨다.
for(int i = 0 ; i < a - 1 ; i++)
{
totalDays += daysOfMonth[i];
}
totalDays += b - 1;
answer = dayOfTheWeek[totalDays%7];
return answer;
}
}
////////////////
자바
class Solution {
public String solution(int a, int b) {
String answer = "";
int[] c = {31,29,31,30,31,30,31,31,30,31,30,31};
String[] MM ={"FRI","SAT","SUN","MON","TUE","WED","THU"};
int Adate = 0;
for(int i = 0 ; i< a-1; i++)
{
Adate += c[i];
}
Adate += b-1;
answer = MM[Adate %7];
return answer;
}
}
import java.time.*;
class Solution {
public String solution(int a, int b) {
return LocalDate.of(2016, a, b).getDayOfWeek().toString().substring(0,3);
}
}
import java.time.*;
class TryHelloWorld
{
public String getDayName(int a, int b)
{
LocalDate date = LocalDate.of(2016, a, b);
return date.getDayOfWeek().toString().substring(0, 3);
}
public static void main(String[] args)
{
TryHelloWorld test = new TryHelloWorld();
int a=5, b=24;
System.out.println(test.getDayName(a,b));
}
}
'프로그래밍' 카테고리의 다른 글
프로그래머스 C# 구슬을 나누는 경우의 수(Combination, using System.Numerics;, P, J) (0) | 2023.01.22 |
---|---|
프로그래머스 C# 나누어 떨어지는 숫자 배열(List sort하기, list.add, List<int>, JAVA) (0) | 2023.01.21 |
프로그래머스 C# 두 정수 사이의 합(삼항연산자, JAVA) (0) | 2023.01.21 |
프로그래머스 C# 올바른 괄호(시간 최소화, 괄호 알고리즘, JAVA) (0) | 2023.01.21 |
프로그래머스 C# 가운데 글자(string 몇 번째 문자 가져오기, JAVA) (0) | 2023.01.21 |