Beautiful Days at the Movies - HackerRank || HackerRank Beautiful Days at the Movies Solution
Problem Name:
Beautiful Days at the Movies
Judge: HackerRank
Problem link: Beautiful Days at the Movies
HackerRank Beautiful Days at the Movies Solution in C
#include <stdio.h>
#include <stdlib.h>
int main()
{
int a, b, c, count = 0;
scanf("%d %d %d", &a, &b, &c);
for (int i = a; i <= b; i++)
{
int p = i, rev = 0;
while (p != 0)
{
rev = rev * 10 + (p % 10);
p = p / 10;
}
if (abs(rev - i) % c == 0) count++;
}
printf("%d\n",count);
return 0;
}
HackerRank Beautiful Days at the Movies Solution in C++/Cpp
#include <bits/stdc++.h>
using namespace std;
int main()
{
int m, n, k, count = 0;
cin >> m >> n >> k;
for (int i = m; i <= n; i++)
{
int number = i, reversed = 0;
while (number != 0)
{
reversed = (reversed * 10) + (number % 10);
number /= 10;
}
if (abs(i - reversed) % k == 0)
{
count++;
}
}
cout << count << endl;
return 0;
}
HackerRank Beautiful Days at the Movies Solution in Java
import java.util.Scanner;
public class Beautiful_Days_at_the_Movies {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int m = input.nextInt();
int n = input.nextInt();
int k = input.nextInt();
int count = 0;
for (int i = m; i <= n; i++) {
int number = i, reversed = 0;
while (number != 0) {
reversed = (reversed * 10) + (number % 10);
number /= 10;
}
if ((Math.abs(i - reversed)) % k == 0) count++;
}
System.out.println(count);
}
}
