C#数组解决约瑟夫环问题
生活随笔
收集整理的這篇文章主要介紹了
C#数组解决约瑟夫环问题
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace 約瑟夫環(huán)
{class Program{static int[] Jose(int total, int start, int alter){int j, k = 0;int[] intCounts = new int[total + 1];int[] intPers = new int[total + 1];for (int i = 0; i < total; i++){intPers[i] = i;}for (int i = total; i >= 2; i--){start = (start + alter - 1) % i;if (start == 0){start = i;}intCounts[k] = intPers[start];k++;for (j = start + 1; j <= i; j++){intPers[j - 1] = intPers[j];}}intCounts[k] = intPers[1];return intCounts;}static void Main(string[] args){int[] intPers = Jose(12, 3, 4);Console.WriteLine("出列順序");for (int i = 0; i < intPers.Length; i++){Console.Write(intPers[i] + " ");}Console.ReadLine();}}
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/shuanglangdeliubei/p/5704097.html
總結(jié)
以上是生活随笔為你收集整理的C#数组解决约瑟夫环问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ansible 部署ssh 偶尔巨慢的解
- 下一篇: c# char unsigned_dll