Qushun

本文介绍了一个使用C#实现的列表处理算法,通过排序、去重和查找连续序列来处理一系列整数数据。该算法展示了如何遍历、操作和筛选列表,以识别特定的数值模式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections;

namespace QuShun
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public int xxxnum = 0;
        public int hutestnum = 1;

        List<int> Pailist = new List<int>();

        private void button1_Click(object sender, EventArgs e)
        {
            Pailist.Add(51);
            Pailist.Add(52);
            Pailist.Add(52);
            Pailist.Add(52);
            Pailist.Add(53);
            Pailist.Add(54);
            Pailist.Add(55);
            Pailist.Add(55);
            Pailist.Add(56);
            Pailist.Add(57);
            Pailist.Add(57);
            Pailist.Add(58);
            Pailist.Add(58);
            Pailist.Add(59);

            label1.Text += Pailist.Count.ToString() + ":";
            for (int i = 0; i < Pailist.Count; i++)
            {
                label1.Text += Pailist[i] + ",";
            }
            hutestnum = 1;
            QuShun(Pailist, xxxnum);
        }

        void QuShun(List<int> _pailist, int xnum)
        {
            _pailist.Sort();
            List<int> Tlist = new List<int>(_pailist.ToArray());
            List<int> Vlist = new List<int>(_pailist.ToArray());
            //_pailist.ForEach(lx => Vlist.Add(lx));


            for (int i = 0; i < Vlist.Count; i++)
            {
                for (int j = i + 1; j < Vlist.Count; j++)
                {
                    if (Vlist[i].Equals(Vlist[j]))
                    {
                        Vlist.RemoveAt(j);
                        if (i > 0)
                        {
                            i--;
                        }
                    }
                }
            }
            bool isfound = false;
            string tt = "";
            //  tt += Tlist.Count.ToString() + ":   ";
            tt += hutestnum.ToString() + ":   ";
            for (int ii = 0; ii < Tlist.Count; ii++)
            {
                tt += Tlist[ii] + ",";
            }
            listBox2.Items.Add(tt);

            for (int i = 0; i < Vlist.Count; i++)
            {
                int TT1 = (int)Vlist[i];
                int TT2 = (int)Vlist[i] + 1;
                int TT3 = (int)Vlist[i] + 2;
                if ((Tlist.Contains(TT2) && Tlist.Contains(TT3)) || Tlist.Count(x => x == TT1) > 2)
                {
                    isfound = true;
                }
            }
            if (isfound == false)
            {
                tt = "";
                //  tt += Tlist.Count.ToString() + ":   ";
                for (int ii = 0; ii < Tlist.Count; ii++)
                {
                    tt += Tlist[ii] + ",";
                }
                //  listBox3.Items.Add(tt);
                listBox3.Items.Add(hutestnum.ToString() + ":" + tt);
                xxxnum = 0;
                hutestnum++;
                //return;
            }
            else
            {
                xxxnum++;
                for (int i = 0; i < Vlist.Count; i++)
                {
                    int TT1 = (int)Vlist[i];
                    int TT2 = (int)Vlist[i] + 1;
                    int TT3 = (int)Vlist[i] + 2;

                    if ((Tlist.Contains(TT2) && Tlist.Contains(TT3)))
                    {
                        Tlist.Remove(TT1); Tlist.Remove(TT2); Tlist.Remove(TT3);
                        listBox1.Items.Add(hutestnum.ToString() + ":" + xxxnum.ToString() + "#   " + TT1.ToString() + "," + TT2.ToString() + "," + TT3.ToString() + "|");
                        QuShun(Tlist, xxxnum);
                        Tlist.Add(TT1); Tlist.Add(TT2); Tlist.Add(TT3);
                        Tlist.Sort();
                    }
                    else if (Tlist.Count(x => x == TT1) > 2)
                    {
                        Tlist.Remove(TT1); Tlist.Remove(TT1); Tlist.Remove(TT1);
                        listBox1.Items.Add(hutestnum.ToString() + ":" + xxxnum.ToString() + "#   " + TT1.ToString() + "," + TT1.ToString() + "," + TT1.ToString() + "|");
                        QuShun(Tlist, xxxnum);
                        Tlist.Add(TT1); Tlist.Add(TT2); Tlist.Add(TT3);
                        Tlist.Sort();
                    }
                }
            }
        }
    }
}

 

转载于:https://my.oschina.net/u/3516766/blog/912927

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值