zoukankan      html  css  js  c++  java
  • 易经计算同根分值的算法

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace dz
    {
    //易经计算同根分值部分算法
    class Program
    {
    static void Main(string[] args)
    {
    float[] dzlist = new float[5];
    dzlist[0] = 10;
    dzlist[1] = 30;
    dzlist[2] = 0;
    dzlist[3] = 10;
    dzlist[4] = 40;

    int index=4;
    System.Console.WriteLine(tgfe(dzlist, index));
    System.Console.ReadKey();
    }

    public static float tgfe(float[] tglist, int index)
    {
    float sum = 0;
    for (int i = 0; i < tglist.Length; i++) {
    if (tglist[i] == 0) continue;
    if (i == index) {
    sum = sum + tglist[index]; continue;
    }
    else if (i < index) {
    int l = i; int r = index;
    for (int j = i; j <=index; j++) {
    if (tglist[j] == 0) {
    if (j == 0) l = 0;
    else l = j-1;
    break;
    } else {
    l = j;
    };
    }
    for (int j = index; j > l; j--)
    {
    if (tglist[j] == 0)
    {
    if (j == tglist.Length - 1) r = tglist.Length - 1;
    else if (j == index)
    {
    r = index;
    }
    else r = j + 1; break;
    }
    else
    {
    r = j;
    }
    }
    switch (r - l) {
    case 0:
    sum = sum + tglist[i] * 1F;
    break;
    case 1: sum = sum + tglist[i] * 0.9F; break;
    case 2: sum = sum + tglist[i] * 0.75F; break;
    case 3: sum = sum + tglist[i] * 0.65F; break;
    case 4: sum = sum + tglist[i] * 0.6F; break;
    default: break;
    }
    }
    else if (i > index) {
    int l = index; int r = i;
    for (int j = index; j <= i; j++)
    {
    if (tglist[j] == 0)
    {
    if (j == 0) l = 0;
    else l = j - 1;
    break;
    }
    else
    {
    l = j;
    };
    }
    for (int j = i; j > l; j--)
    {
    if (tglist[j] == 0)
    {
    if (j == tglist.Length - 1) r = tglist.Length - 1;
    else if (j == index)
    {
    r = index;
    }
    else r = j + 1; break;
    }
    else
    {
    r = j;
    }
    }
    switch (r - l)
    {
    case 0:
    sum = sum + tglist[i] * 1F;
    break;
    case 1: sum = sum + tglist[i] * 0.9F; break;
    case 2: sum = sum + tglist[i] * 0.75F; break;
    case 3: sum = sum + tglist[i] * 0.65F; break;
    case 4: sum = sum + tglist[i] * 0.6F; break;
    default: break;
    }

    }

    }

    return sum;
    }
    }
    }

  • 相关阅读:
    php hook example
    sql 建立数据库,表格,索引,主键
    js 高级函数 之示例
    js 事件
    DOM 操作内容 innerText/innerHTML
    DOM 之 document 查找元素方法
    BOM 之 screen history
    Hadoop源码篇--Client源码
    Spark算子篇 --Spark算子之combineByKey详解
    Pandas库的使用--Series
  • 原文地址:https://www.cnblogs.com/sunwubin/p/3435445.html
Copyright © 2011-2022 走看看