110,533
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.IO;
using System.Collections.Generic;
class Program
{
static void Main()
{
int[] arr = new int[]{1,1,1,2,3,3,3,4,5,6,6};
List<MyTag> lst = new List<MyTag>();
MyTag tag = new MyTag() { data = arr[0], len = 1, pos = 0 };
for (int i = 1; i < arr.Length; i++)
{
if (tag.data == arr[i])
{
tag.len++;
}
else
{
//if (tag.len > 1)
//{
lst.Add(tag);
//}
tag.data = arr[i];
tag.len = 1;
tag.pos = i;
}
}
//if (tag.len > 1)
//{
lst.Add(tag);
//}
foreach (var v in lst)
{
Console.WriteLine("{0}:{1}-{2}", v.data, v.pos, v.pos + v.len - 1);
}
}
}
struct MyTag
{
public int data;
public int pos;
public int len;
}
for (int i = 1; i < arr.Length; i++)
{
if (tag.data == arr[i])
{
tag.len++;
}
else
{
//if (tag.len > 1)
//{
lst.Add(tag);
//}
tag.data = arr[i];
tag.len = 1;
tag.pos = i;
}
}
using System;
using System.IO;
using System.Collections.Generic;
class Program
{
static void Main()
{
int[] arr = new int[]{1,1,1,2,3,3,3,4,5,6,6};
List<MyTag> lst = new List<MyTag>();
MyTag tag = new MyTag() { data = arr[0], len = 1, pos = 0 };
for (int i = 1; i < arr.Length; i++)
{
if (tag.data == arr[i])
{
tag.len++;
}
else
{
if (tag.len > 1)
{
lst.Add(tag);
}
tag.data = arr[i];
tag.len = 1;
tag.pos = i;
}
}
if (tag.len > 1)
{
lst.Add(tag);
}
foreach (var v in lst)
{
Console.WriteLine("{0}:{1}-{2}", v.data, v.pos, v.pos + v.len - 1);
}
}
}
struct MyTag
{
public int data;
public int pos;
public int len;
}