๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm๐Ÿฐ/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] 2016๋…„ basic

by Jouureee 2021. 2. 24.

๋ฌธ์ œ :

programmers.co.kr/learn/courses/30/lessons/12901?

 

์ฝ”๋”ฉํ…Œ์ŠคํŠธ ์—ฐ์Šต - 2016๋…„

2016๋…„ 1์›” 1์ผ์€ ๊ธˆ์š”์ผ์ž…๋‹ˆ๋‹ค. 2016๋…„ a์›” b์ผ์€ ๋ฌด์Šจ ์š”์ผ์ผ๊นŒ์š”? ๋‘ ์ˆ˜ a ,b๋ฅผ ์ž…๋ ฅ๋ฐ›์•„ 2016๋…„ a์›” b์ผ์ด ๋ฌด์Šจ ์š”์ผ์ธ์ง€ ๋ฆฌํ„ดํ•˜๋Š” ํ•จ์ˆ˜, solution์„ ์™„์„ฑํ•˜์„ธ์š”. ์š”์ผ์˜ ์ด๋ฆ„์€ ์ผ์š”์ผ๋ถ€ํ„ฐ ํ† ์š”์ผ๊นŒ

programmers.co.kr

 

๋ถ„์„ :

์œค๋…„๊ณผ 7์›”์—์„œ 8์›”๋กœ ๋„˜์–ด๊ฐˆ ์‹œ ํ™€์ˆ˜ ์ง์ˆ˜ ๊ณ„์‚ฐ์„ ๋‹ฌ๋ฆฌ ํ•ด์ค€๋‹ค. 

 

c++ ํ’€์ด :

#include <string>
#include <vector>
#include <iostream>

using namespace std;

string solution(int a, int b) {
    string answer = "";
    int sum = 0;
    //int day = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    if(a>1){
       for(int i =1; i < a; i++){
           if(i <= 7){
            if(i % 2 == 1) {
                sum += 31;
            } else{
                if (i == 2){
                    sum += 29;
                }else{
                    sum += 30;
                }
            } 
           }
           else{
              if(i % 2 == 0) {
                sum += 31;
            }else{
                sum += 30;
            }  
           }
       }
        
       sum += b;  
    } 
    else{
        sum = b;
    }
    
    if(sum % 7 == 1){
        answer = "FRI";
    }else if( sum % 7 == 2){
        answer = "SAT";
    }else if(sum % 7 == 3){
        answer = "SUN";
    }else if(sum % 7 == 4){
        answer = "MON";
    }else if(sum % 7 == 5){
        answer = "TUE";
    }else if(sum % 7 == 6){
        answer = "WED";
    }else if(sum % 7 == 0){
        answer = "THU";
    }
    
    return answer;
}

๋Œ“๊ธ€