查找
重複------- 1,2,3,4,2,5 --->重複數丟失號碼----- 1,2,3,5,6,7- --->數爲3之間缺少 - 1,2,4- 5
缺失順序---------,在整數數組3,5 ---->數字不是爲了在3,4
我的代碼是:
private void Comparepagenumbers(int[] Pages, char type,string msg)
{
if (Pages.Length > 0)
{
if (Pages[0] != 1)
{
if (type == 'N')
report("Error [R6223E069]: Numeric " + msg + "s are started with " + Pages[0]);
if (type == 'R')
report("Error [R6223E070]: Roman " + msg + "s are started with " + Pages[0]);
}
for (int i = 0; i < Pages.Length; i++)
{
int chk = 0;
if (Pages[i] == -1)
{
i--;
Pages = Pages.Where((val, idx) => idx != i).ToArray();
continue;
}
for (int j = 0; j < Pages.Length; j++)
{
if (Pages[i] == Pages[j])
{
chk++;
if (chk > 1)
{
if (type == 'N')
report("Error [R6223E071]: Duplicate " + msg + "s exist. First id [" + Pages[i] + "] next id [" + Pages[j] + "].");
if (type == 'R')
report("Error [R6223E072]: Duplicate Roman " + msg + "s exist. First id [" + Pages[i] + "] next id [" + Pages[j] + "].");
Pages = Pages.Where((val, idx) => idx != j).ToArray();
chk--;
j--;
}
}
}
}
int[] XNP = new int[Pages.Length];
Array.Copy(Pages, XNP, Pages.Length);
int i1, j1, k1, temp;
string temp_currChap = string.Empty;
string temp_FullName = string.Empty;
for (i1 = 0; i1 < XNP.Length; i1++)
{
for (j1 = 0; j1 < i1; j1++)
{
if (XNP[j1] > XNP[i1])
{
temp = XNP[j1];
XNP[j1] = XNP[i1];
for (k1 = i1; k1 > j1; k1--)
{
XNP[k1] = XNP[k1 - 1];
}
XNP[k1 + 1] = temp;
}
}
}
for (int i = 0; i < XNP.Length; i++)
{
if (i < XNP.Length - 1)
{
if (XNP[i] + 1 != XNP[i + 1])
{
if (type == 'N')
report("Error [R6223E073]: " + msg + "s Missing between " + XNP[i] + " - " + XNP[i + 1]);
if (type == 'R')
report("Error [R6223E074]: " + msg + "s missing between " + XNP[i] + " - " + XNP[i + 1]);
}
}
}
for (int i = 0; i < Pages.Length;)
{
if (XNP[i] != Pages[i])
{
int numIndex = Array.IndexOf(XNP, Pages[i]);
if (type == 'N')
report("Error [R6223E076]: " + msg + " is not in order at " + Pages[i]);
if (type == 'R')
report("Error [R6223E077]: " + msg + " is not in order at " + Pages[i]);
XNP = XNP.Where((val, idx) => idx != numIndex).ToArray();
}
else
{
XNP = XNP.Where((val, idx) => idx != i).ToArray();
}
Pages = Pages.Where((val, idx) => idx != i).ToArray();
}
}
}
}
其工作
,但我的要求,如果輸入1,2,3,4,8,9,10,11,12,13,14,15,16,5,6,7 ,17,18,19,20
輸出不是爲了在4-8,16-5,7-17
,但它在8,9,10,11,12給不按順序, 13,14,15,16
注意:在這裏,我檢查羅馬數字第一第二數字序數i轉換羅馬數字到數字與邏輯的通作爲申辯第一個秒數字。所以我可以通過條件分開他們。
這是不是某種功課,是它;)? –
這是什麼問題? –
什麼是你確定哪些不合適的邏輯?如果你把8-16移到了正確的地方,那麼他們就會處於正確的狀態,所以這些都是錯誤的......我當然沒有看到這樣的邏輯:4-8不是有序的,因爲它們是,只是碰巧有一個5,6,7後,不是爲了... – Chris