Advertisement
Avdluna

Untitled

Oct 15th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int n,i,x[10001],a=1,f=0;
  7.  
  8.     while(1){
  9.          
  10.            scanf("%d",&n);
  11.  
  12.     if(n==0){
  13.        
  14.         break;
  15.     }
  16.  
  17.     else{
  18.                 for(i=0 ; i < n ; i++){
  19.                     scanf("%d",&x[i]);
  20.                 }
  21.  
  22.                 for(i=0 ; i< n-2 ; i++){
  23.                     if((x[a] > x[i] && x[a] > x[i+2]) || (x[a] < x[i] && x[a] < x[i+2])){
  24.                         f++;
  25.  
  26.                     }
  27.                             a++;
  28.                 }
  29.  
  30.                 if((x[0] > x[n-1] && x[0] > x[1]) || (x[0] < x[n-1] && x[0] < x[1])){
  31.                     f++;
  32.                 }
  33.  
  34.                 if(x[n-1] > x[n-2] && x[n-1] > x[0] || x[n-1] < x[n-2] && x[n-1] < x[0]){
  35.                     f++;
  36.                 }
  37.  
  38.  
  39.             printf("%d\n",f);
  40.             f=0;
  41.             a=1;
  42.  
  43.     }
  44. }
  45.  
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement