修改的错误为添加如下判断
if (A > C) J = A, A = C, C = J, k = true;
测试用例
程序代码:
int aa[] = { 99, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 55, 5, 44, 4, 33, 3, 22, 2, 11, 1, 99, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6, 9, 88, 8, 77, 7, 66, 6 }, xu = 0, ci = 0, j = 0, jian = 0, lian = sizeof(aa) / sizeof(aa[0]); bool k = false;