Sunday, 3 September 2017

CodeForce Problem 849A - Odds and Ends Solution (C++)

Problem:

You can see the question to the problem here.


Solution:

This is the simplest problem I ever had, just implement the given formulas! However, it does take me some time to write.

Code:

#include <bits/stdc++.h>
using namespace std;
main(){
int n;
int s[101];
cin>>n;
for(int i=0;i<n;i++){
    cin>>s[i];   //Numbers are stored into array
}

/*Algorithm explanation
//when n is divided by 2 remainder is not 0, result is always odd.
//Plus First element and last element.. both of them must always be odd for this Algorithm to work as mentioned in question. */

(n%2 && s[0]%2 && s[n-1]%2)?cout<<"Yes":cout<<"No";  //Another form of if else.

}

No comments:

Post a Comment

Spoj Problem ACMCEG2C - Pick the candies (C++)

  The problem link may be found here.       Explanation: Use Deque to keep track of elements of the variety of candies. If i is gre...