Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- You are given N integers (given in a single line, separated by a space).
- Write a program that checks whether the product of the odd elements is equal to the product of the even elements.
- Elements are counted from 1 to N, so the first element is odd, the second is even, etc.
- http://judge.telerikacademy.com/problem/10oddevenproduct
- */
- var n = gets();
- var input = gets().split(' ');
- var productOdd = 1;
- var productEven = 1;
- for (let i = 0; i < n; i++) {
- if ((i % 2) != 0) {
- productOdd *= input[i];
- } else {
- productEven *= input[i];
- }
- }
- if (productOdd == productEven){
- print("yes " + productEven);
- }
- else{
- print("no " + productEven + " " + productOdd);
- }
- // C# =================================================================
- using System;
- //16 mb is very little!!!!!!
- class OddorEvenProduct
- {
- static void Main()
- {
- ulong numbers = 5 ;// ulong.Parse(Console.ReadLine());//
- ulong productOdd = 1, productEven = 1;
- string input = "2,1,1,6,3";// Console.ReadLine();//
- for (ulong i = 0; i < numbers; i++)
- if ((i % 2) != 0)
- productOdd *= ulong.Parse(input.Split(',')[i]);
- else
- productEven *= ulong.Parse(input.Split(',')[i]);
- if (productOdd == productEven)
- Console.WriteLine("yes {0}", productEven);
- else
- Console.WriteLine("no {1} {0}", productEven, productOdd);
- Console.ReadKey();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement