标签:temp bsp eof class main [] col printf std
无聊想的题目,但题目创意改自从一组无序数组中找不存在的最小正整数。并不难,但也有陷阱,比考虑0和负数...
/**
* 从无序数组中找不存在的最小正整数
* 我的要求:比如:{3,4,6,9,20}中 最小的不存在的正整数为2
*/
#include <stdio.h>
int main()
{
int arr[] = {-5, -10, 42, 29, 18, -3, 8, 20, -1};
int i, j, temp;
for(i = 1; i < sizeof(arr)/sizeof(int); i++)
{
j = i - 1;
if(arr[j] < arr[i] && arr[j] > 0)
temp = arr[j];
}
temp --;
printf("%d\n", temp);
return 0;
}
标签:temp bsp eof class main [] col printf std
原文地址:http://www.cnblogs.com/darkchii/p/7571976.html