Sunday, April 30, 2017

URI Solution 1089 Musical Loop - Solution in C++ | Ad Hoc

URI Solution 1089 Musical Loop -  Solution in C++ | Ad Hoc



URI Online Judge Solution  | Ad Hoc


Problem Name: URI Problem - Musical Loop
Problem Number : URI - 1089
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus

URI Solution 1089 Code in CPP:

#include <cstdio>

int array[10005];

int main()
{
 int n = 0;
 int i = 0;
 int x = 0;
 
 scanf("%d", &n);
 
 while(n != 0)
 {
  x = 0;
  for(i = 0; i < n; i++)
  {
  scanf("%d", &array[i]);
  }
 
  for(i = 0; i < n; i++)
  {
   if(array[i] < array[(i + 1)%n])
   {
    if(array[(i + 1)%n] > array[(i + 2)%n])
    {
     x++;
    }
    
   }
   
   if(array[i] > array[(i + 1)%n])
   {
    if(array[(i + 1)%n] < array[(i + 2)%n])
    {
     x++;
    }
    
   }
  }
  printf("%d\n", x);
  scanf("%d", &n);
  
 }
 
 return 0;
 
}

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.