#include <stdio.h> int n; int a[8000000]; int i,j; int compare_int( const void* a, const void* b ) { if( *(int*)a == *(int*)b ) return 0; return *(int*)a < *(int*)b ? -1 : 1; } int main(){ scanf("%d\n", &n); for(i = 0; i < n; i++){ scanf("%d", &a[i]); } qsort(a, n, sizeof(int), compare_int); for(i=1; a[i] > 0; i++){ if(a[i-1] == a[i]) { j = i; while(a[j+1] == a[i]) j++; a[j] = a[i]+1; } } printf("%d", a[i-1]); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <stdio.h> int n; int a[8000000]; int i,j; int compare_int( const void* a, const void* b ) { if( *(int*)a == *(int*)b ) return 0; return *(int*)a < *(int*)b ? -1 : 1; } int main(){ scanf("%d\n", &n); for(i = 0; i < n; i++){ scanf("%d", &a[i]); } qsort(a, n, sizeof(int), compare_int); for(i=1; a[i] > 0; i++){ if(a[i-1] == a[i]) { j = i; while(a[j+1] == a[i]) j++; a[j] = a[i]+1; } } printf("%d", a[i-1]); return 0; } |