发现吨[]阵列中的坂本的算法找到周的天阵列、算法、发现

2023-09-11 07:27:53 作者:Tattoo (纹身)

我想知道如何找到如何计算的 T [] 数组这个算法?

  INT陶氏(INT Y,INT男,INT D)
{

   静态INT吨[] = {0,3,2,5,0,3,5,1,4,6,2,4};

   Ÿ -  = M< 3;

   收益率(Y + Y / 4  -  Y / 100 + Y / 400 + T [M-1] + D)%7;

}
 

解决方案

您可以使用 code以下产生所需的阵列

 的#include< stdio.h中>

诠释的主要(无效){
    INT改编[] = {31,28,31,30,31,30,31,31,30,31,30,31};
    INT totalDaysInThisYear = -1,米; / *奇偶将使totalDaysInThisYear = 0 * /
    为(M = 1; M&其中; = 12; ++米){
        const int的奇偶性=(M< 3);
        的printf(%D \ N(totalDaysInThisYear +奇偶校验)%7);
        totalDaysInThisYear + = ARR [M  -  1];
    }
    返回0;
}
 
算法 最短路径之弗洛伊德 Floyd 算法

I wanna know how to find how to calculate the values of t[] array in this algorithm?

int dow(int y, int m, int d)        
{        

   static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};        

   y -= m < 3;        

   return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;        

}

解决方案

You can use code below to generate the required array

#include <stdio.h>

int main(void) {
    int arr[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    int totalDaysInThisYear = -1, m;  /* Parity would make totalDaysInThisYear = 0 */
    for(m = 1; m <= 12; ++m) {
        const int parity = (m < 3);
        printf("%d\n", (totalDaysInThisYear + parity) % 7);
        totalDaysInThisYear+= arr[m - 1];
    }
    return 0;
}