Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://www.careercup.com/question?id=14960662
- #include <stdio.h>
- int main()
- {
- int a[] = {1, 2, -1, 0, 7, 6, 5};
- const int N = sizeof(a)/sizeof(a[0]);
- int i = 0;
- for(int s = 1; s < N-2; ++s)
- {
- if(a[s] < a[i]) { i = s;}
- else if(a[s] > a[i]) { break;}
- }
- int k = N - 1;
- for(int s = N - 2; s > i; --s)
- {
- if(a[s] > a[k]) { k = s; }
- else if(a[s] < a[k]) { break; }
- }
- for(int j = i+1; j < k; ++j)
- {
- if(a[i] < a[j] && a[j] < a[k])
- {
- printf("%d, %d, %d\n", a[i], a[j], a[k]);
- return 0;
- }
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment