R再次感谢您的解释。:)相信我,我只想告诉你人们通过他们的书、博客和答案告诉我的是什么。祝C#好运!隐马尔可夫模型。。这里的输入是什么?这是我的数组吗?是的,输入的是你的数组。因为我不能理解它的头尾。但我会的!请原谅我的艺术。。。实际上,如果该位令人困惑,
R再次感谢您的解释。:)相信我,我只想告诉你人们通过他们的书、博客和答案告诉我的是什么。祝C#好运!隐马尔可夫模型。。这里的输入是什么?这是我的数组吗?是的,输入的是你的数组。因为我不能理解它的头尾。但我会的!请原谅我的艺术。。。实际上,如果该位令人困惑,,c#,linq,C#,Linq,R再次感谢您的解释。:)相信我,我只想告诉你人们通过他们的书、博客和答案告诉我的是什么。祝C#好运!隐马尔可夫模型。。这里的输入是什么?这是我的数组吗?是的,输入的是你的数组。因为我不能理解它的头尾。但我会的!请原谅我的艺术。。。实际上,如果该位令人困惑,请告诉我-(x=>0) // Sorted Input: 1, 2, 3, 5 Print: 1 // Not sorted Input: 2, 1, 3, 6 Print: 0 // Sorted, but with duplicates
R再次感谢您的解释。:)相信我,我只想告诉你人们通过他们的书、博客和答案告诉我的是什么。祝C#好运!隐马尔可夫模型。。这里的
输入是什么?这是我的数组吗?是的,输入的是你的数组。因为我不能理解它的头尾。但我会的!请原谅我的艺术。。。实际上,如果该位令人困惑,请告诉我-(x=>0)
// Sorted
Input: 1, 2, 3, 5
Print: 1
// Not sorted
Input: 2, 1, 3, 6
Print: 0
// Sorted, but with duplicates
Input: 2, 2, 3, 7
Print: 2
int arrayLength = 0;
int prev, next;
int sortStatus = 1;
Console.Write("Input array Length: ");
arrayLength = Convert.ToInt32(Console.ReadLine());
int[] ar = new int[arrayLength];
for (int x = 0; x < arrayLength; x++)
{
Console.Write("Input {0} value: ", (x+1).ToString());
ar[x] = Convert.ToInt32(Console.ReadLine());
}
for (int x = 0; x < ar.Length-1; x++)
{
prev = (int)ar[x];
next = (int)ar[x + 1];
if (next < prev)
sortStatus = 0;
if (next == prev)
sortStatus = 2;
}
Console.Write(sortStatus.ToString());
Console.Read();
if (ar.SequenceEqual(ar.OrderBy(x => x)))
{
if (ar.Distinct().Count() == ar.Length)
return 1;
else
return 2;
}
else
{
return 0;
}
var input = new int[] { 1, 2, 3, 4, 5 };
var output = input.Zip(input.Skip(1), (a, b) => new {a=a, b=b})
.Aggregate(1, (status, x) => status == 0 ? 0 : ((x.a > x.b ? 0 : (x.a == x.b ? 2 : status))));
if (next < prev)
sortStatus = 0;
if (next == prev)
sortStatus = 2;
static int EvaluateArray(int[] array)
{
int? lastItem = null;
bool match = false;
foreach (int item in array)
{
if (item < lastItem)
return 0;
else if (item == lastItem)
match = true;
lastItem = item;
}
if (match)
return 2;
return 1;
}
IEnumerable<int> signs =
from i in Enumerable.Range(0, ar.Length).Skip(1)
select ar[i-1].CompareTo(ar[i]);
int result =
signs.Any(sign => sign < 0) ? 0 :
signs.All(sign => 0 < sign) ? 1 :
2;
int minSign = !ar.Skip(1).Any() ? 1 :
(
from i in Enumerable.Range(0, ar.Length).Skip(1)
select ar[i-1].CompareTo(ar[i])
).TakeWhile(x => 0 <= x).Min();
int result =
minSign < 0 ? 0 :
0 < minSign ? 1 :
2;