In this article, we delve into the solution for the Codeforces problem "Watermelon" (Problem 4A).
Click the link to see detailed Problem Description https://codeforces.com/problemset/problem/4/A
Codeforces is a popular platform for competitive programming, offering a variety of algorithmic challenges to hone one's coding skills. The Watermelon problem, a classic in the realm of programming puzzles, presents an interesting challenge that tests both logic and coding proficiency. In this discussion, we explore the intricacies of the problem statement and provide a detailed solution approach to tackle it effectively.
Description
- Include the iostream library to enable input and output operations.
- Declare that you'll be using the std namespace to avoid writing "std::" before every standard library function.
- Start the main function.
- Declare an integer variable named 'w' to store the input.
- Receive input for 'w' using the cin stream.
- Check if 'w' is even and greater than 2 using the modulo operator (%) and logical AND operator (&&).
- If the condition is true, output "YES" indicating that 'w' satisfies the conditions.
- If the condition is false, output "NO" indicating that 'w' does not satisfy the conditions.
- End the main function.
- Return 0 to indicate successful execution.
CODE
C++
#include <iostream>
using namespace std;
int main()
{
int w;
cin >> w;
if (w % 2 == 0 && w > 2)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return 0;
}
C
#include <stdio.h>
int main() {
int w;
scanf("%d", &w);
if (w % 2 == 0 && w > 2) {
printf("YES\n");
} else {
printf("NO\n");
}
return 0;
}
In C, we use printf and scanf for input and output instead of cout and cin.