Jumping on the Clouds: Revisited - HackerRank || HackerRank Jumping on the Clouds: Revisited Solution

Problem Name: Jumping on the Clouds: Revisited
Judge: HackerRank



HackerRank Jumping on the Clouds: Revisited Solution in C

#include <stdio.h>

int main()
{
    int n;
    int k;
    scanf("%d %d", &n, &k);
    int clouds[n];

    for (int i = 0; i < n; i++)
    {
        scanf("%d", &clouds[i]);
    }

    int CurrentClouds = 0;
    int energy = 100;

    do
    {
        CurrentClouds = ((CurrentClouds + k) % n);
        energy--;

        if (clouds[CurrentClouds] == 1)
        {
            energy = energy - 2;
        }

    }
    while (CurrentClouds % n != 0);

    printf("%d\n", energy);

    return 0;
}


HackerRank Jumping on the Clouds: Revisited Solution in C++/Cpp

#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    int k;
    cin >> n >> k;
    int clouds[n];

    for (int i = 0; i < n; i++)
    {
        cin >> clouds[i];
    }

    int CurrentClouds = 0;
    int energy = 100;

    do
    {
        CurrentClouds = ((CurrentClouds + k) % n);
        energy--;

        if (clouds[CurrentClouds] == 1)
        {
            energy = energy - 2;
        }

    } while (CurrentClouds % n != 0);

    cout << energy << endl;

    return 0;
}


HackerRank Jumping on the Clouds: Revisited Solution in Java

import java.util.Scanner;

public class Jumping_on_the_Cloud {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        int[] clouds = new int[n];
        for (int i = 0; i < n; i++) clouds[i] = input.nextInt();
        int energy = 100, CurrentClouds = 0;
        do {
            CurrentClouds = ((CurrentClouds + k) % n);
            energy--;
            if (clouds[CurrentClouds] == 1) {
                energy = energy - 2;
            }
        } while (CurrentClouds % n != 0);
        System.out.println(energy);
    }
}





Next Post Previous Post
No Comment
Add Comment
comment url