如何判断一组号码中是否有连续5次以上的连号,并删除 循环。用个arraylist,如果两个数字相邻就写入,arraylist.count>5就... 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 循环一次,然后使用字典来存放编号和他出现的次数,泛型字典Dictionary<string, int> dic = new Dictionary<string, int>(); 1,将数字全排序。2,遍历原数组3,当指向第N个数字array[n]的时候,看一下a[n+5] == a[n] + 5 如果是,则删除a[n] ~ a[n+5]如果是删除所有相连数字,要增加循环处理后面的“5”,让他自增到不满足条件或到末尾为止 string [] stringArray=new string(.....)//用于存放需要判断的队列string [] stringArray_new = new string[90];//用于存放判断后的队列。int j=0;//计数器int num = stringArray[0].toInt();//前一个数int num2 = stringArray[1].toInt();//后一个数int k=0;//用于结果数组的下标。for (int i=0;i < stringArray.length -1 ; i++){ // 判断相邻两个数据是否连号 if (num2 == (num + 1)) { j = j + 1; } else { j = 0; } //取下一个数。 num = stringArray[i + 1].toInt(); num2 = stringArray[i + 2].toInt(); //如果连号,并连号超过五个数,结果数组下标回拨5, if (j > 5) { k = k -5; } else { stringArray_new[k] = stringArray[i]; } }以上代码未经测试,仅是思路供参考。 不考虑文件操作部分,仅从算法的角度的话,仅仅是一个思路,没有验证public static List<int> ModifyList(int List<int> source){List<int> result=new List<int>();int LineNum=0;while(true){List<int> tempList=new List<int>();Floater=LineNum;tempList.Add(source[LineNum]);while( LineNum<=source.Count-2){ if(source[LineNum]++== source[LineNum++])tempList.Add(source[LineNum]);else{ break; if( LineNum-Floater<5)AppendToFinalList(tempList,result); }}if(LineNum==source.Count-1)break;}return result;} C#Windows不安全代码封送异常处理 用C# 如何做一个声控flash C#与SQL数据库连接 C# 算法二叉树 问题,急!谢谢帮助!!! 急`如何将 32位二进制 解码成单精度浮点数? 如何取得博客和新闻的评论信息 关于DataGridView设置DispalyIndex后显示顺序不正确问题 关于地址空间! 讨论:关于C#下操作Word文档用户权限的问题 SqlConnection关闭后的释放问题 如何等待一个进程结束??? 两个combox的问题
Dictionary<string, int> dic = new Dictionary<string, int>();
2,遍历原数组
3,当指向第N个数字array[n]的时候,看一下a[n+5] == a[n] + 5
如果是,则删除a[n] ~ a[n+5]如果是删除所有相连数字,要增加循环处理后面的“5”,让他自增到不满足条件或到末尾为止
int num = stringArray[0].toInt();//前一个数
int num2 = stringArray[1].toInt();//后一个数int k=0;//用于结果数组的下标。
for (int i=0;i < stringArray.length -1 ; i++)
{
// 判断相邻两个数据是否连号
if (num2 == (num + 1))
{
j = j + 1;
}
else
{
j = 0;
}
//取下一个数。
num = stringArray[i + 1].toInt();
num2 = stringArray[i + 2].toInt(); //如果连号,并连号超过五个数,结果数组下标回拨5,
if (j > 5)
{
k = k -5;
}
else
{
stringArray_new[k] = stringArray[i];
}
}
以上代码未经测试,仅是思路供参考。
public static List<int> ModifyList(int List<int> source){
List<int> result=new List<int>();
int LineNum=0;while(true)
{
List<int> tempList=new List<int>();
Floater=LineNum;
tempList.Add(source[LineNum]);
while( LineNum<=source.Count-2)
{
if(source[LineNum]++== source[LineNum++])
tempList.Add(source[LineNum]);
else
{
break;
if( LineNum-Floater<5)
AppendToFinalList(tempList,result);
}}
if(LineNum==source.Count-1)
break;}
return result;}