gpt4 book ai didi

c# - 编程逻辑! :O

转载 作者:行者123 更新时间:2023-11-30 18:55:16 26 4
gpt4 key购买 nike

因为缺乏看似合理的编程逻辑而难过..

在 SSIS 的脚本任务中。需要做一些数据转换..如下..

switch(LeadTime)
{

case: 1

WM1 = DAY1
WM2 = DAY2
WM3 = DAY3
WM4 = DAY4
WM5 = DAY5
WM6 = DAY6
WM7 = DAY7


case: 2

WM1 = DAY1 + DAY2
WM2 = DAY2 + DAY3
WM3 = DAY3 + DAY4
WM4 = DAY4 + DAY5
WM5 = DAY5 + DAY6
WM6 = DAY6 + DAY7
WM7 = DAY7 + DAY1


case: 3


WM1 = DAY1 + DAY2 + DAY3
WM2 = DAY2 + DAY3 + DAY4
WM3 = DAY3 + DAY4 + DAY5
WM4 = DAY4 + DAY5 + DAY6
WM5 = DAY5 + DAY6 + DAY7
WM6 = DAY6 + DAY7 + DAY1
WM7 = DAY7 + DAY1 + DAY2


..................

case: 7

WM1 = DAY1 + DAY2 + DAY3 + DAY4 + DAY5 + DAY6 + DAY7
WM2 = DAY2 + DAY3 + DAY4 + DAY5 + DAY6 + DAY7 + DAY1
WM3 = DAY3 + DAY4 + DAY5 + DAY6 + DAY7 + DAY1 + DAY2
WM4 = DAY4 + DAY5 + DAY6 + DAY7 + DAY1 + DAY2 + DAY3
WM5 = DAY5 + DAY6 + DAY7 + DAY1 + DAY2 + DAY3 + DAY4
WM6 = DAY6 + DAY7 + DAY1 + DAY2 + DAY3 + DAY4 + DAY5
WM7 = DAY7 + DAY1 + DAY2 + DAY3 + DAY4 + DAY5 + DAY6


}

我如何围绕它构建一个循环以使其成为良好的编程?我很茫然,因为它在中间值之后从两端添加..

这就是我能做的! :O

case: 7

for(int i=0;i<LeadTime;i++)
{
WM1 += Array[i];
WM2 += Array[i];
...
WM7 += Array[i];
}

最佳答案

您可以使用模数来环绕。这应该适用于所有人:

WM = new int[7];
for (int i = 0; i < LeadTime; i++) {
for (int j = 0; j < WM.Length; j++) {
WM[j] += Array[(i + j) % 7];
}
}

关于c# - 编程逻辑! :O,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5518828/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com