c# 窗体猴子选大王
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{/*顺序表应用*/
int n,m, d, i, count,pos=0; string t=""; //n代表猴子个数,m代表要淘汰的报数,d代表淘汰的猴子个数,count代表报数记录
textBox3.Clear(); textBox4.Clear();
n = int.Parse(textBox1.Text); m = int.Parse(textBox2.Text);
int[] A = new int[n];
for (i=0;i<n;i++) A[i]=i+1;
//出队前:
for (i = 0; i < n; i++) t = t + A[i]+" "; textBox3.Text = t;
//出队后:
count=0;
d=0; /*d记录退出圈外的猴子个数*/
while (d<n)
for (i=0;i<n;i++)
if (A[i]!=0)
{
count++;
if (count==m) /*第i个猴子退出*/
{
textBox4 .Text =textBox4 .Text + A[i].ToString ()+" ";
count=0; /*计数器重置为0*/
d++; pos = i;
}