Question 3

10 comments on “Question 3”


  • culbgaming12

    #include
    using namespace std;

    int main()
    {
    int k, n;
    cin >> n >> k;
    int clouds[n];
    for (int i = 0; i > clouds[i];
    }

    int e = 100;
    int g = 0;
    while (true)
    {
    g = (g + k) % n;

    if (clouds[g] == 1)
    {
    e -= 3;
    }

    else
    {
    e–;
    }
    if (g == 0)
    {
    break;
    }
    }

    cout << e << endl;
    return 0;
    }


  • banawariswami123

    import java.util.*;

    class prep1{

    public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    int k = sc.nextInt();

    int e = 100;

    int[] c = new int[n];

    for(int i = 0; i 0){

    e = e-1;

    i = (i+k)%n;

    if(c[i] == 1){

    e = e-2;

    }

    if(i == 0){

    break;

    }

    }

    System.out.println(e);

    }

    }


  • banawariswami123

    import java.util.*;

    class prep1{

    public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    int k = sc.nextInt();

    int e = 100;

    int[] c = new int[n];

    for(int i = 0; i 0){

    e = e-1;

    i = (i+k)%n;

    if(c[i] == 1){

    e = e-2;
    }

    if(i == 0){

    break;
    }
    }

    System.out.println(e);

    }

    }


  • dwivedianimesh71

    def Clouds(c, k):
    i , s = 0 , 100
    while (i+k)%n:
    s -= 3 if c[(i+k)%n] else 1
    i += k
    s -= 3 if c[0] else 1
    return s
    n , k = map(int,input().split())
    c = list(map(int,input().split()))
    print(Clouds(c, k))

    #This would one of the most efficienct code i think


  • abhitejkumarvoruganti

    #!/bin/python3

    import math
    import os
    import random
    import re
    import sys

    # Complete the jumpingOnClouds function below.
    def jumpingOnClouds(c, k, n):
    m=n
    j=k
    e=100
    if k==n:
    if c[0]==1:
    return e-3
    else:
    return e-1
    while True:
    if c[j]==1:
    e=e-3
    n=n-k
    j=j+k
    if j>=m:
    j=j-m
    else:
    e=e-1
    n=n-k
    j=j+k
    if j>=m:
    j=j-m
    if n<=0:
    n=m+n
    if m==n:
    break
    return e

    if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    nk = input().split()

    n = int(nk[0])

    k = int(nk[1])

    c = list(map(int, input().rstrip().split()))

    result = jumpingOnClouds(c, k, n)

    fptr.write(str(result) + '\n')

    fptr.close()


  • Ankita

    import java.util.Scanner;

    public class JumpingOnClouds {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();// number of clouds
    int k = sc.nextInt();// size of jump c[(i+k)%n]
    int[] c = new int[n];
    for( int i=0;i<n;i++) {
    c[i] = sc.nextInt();
    }

    jumpingOfClouds(c,k,n);

    }

    public static void jumpingOfClouds(int[]c,int k,int n) {
    int e =100;
    int i=0;
    int modulo = (i+k)%n;//
    while(modulo!=0) {
    modulo = (i+k)%n;
    int position = c[modulo];
    if(position==1) {
    e= e-3;
    }
    else {
    e=e-1;
    }

    i=modulo;
    // System.out.println(i);
    }
    System.out.println(e);
    }
    }


  • Snehal

    import java.util.*;
    public class Main
    {
    public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int energy = 100;
    int size = s.nextInt();
    int jump = s.nextInt();
    int arr[] = new int[size];
    for(int i=0;i<size;i++){
    arr[i] = s.nextInt();
    }
    for(int i=0;i<size;i=jump+i)
    {
    if(arr[i]==0){
    energy = energy – 1;
    }
    else {
    energy = energy – 3;
    }
    }
    System.out.println(energy);
    }
    }


  • Debparna

    import java.util.*;
    public class Main
    {
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.nextLine();
    String list[] = str.split(” “);
    int n = Integer.parseInt(list[0]);
    int k = Integer.parseInt(list[1]);
    int arr[] = new int[n];
    str = sc.nextLine();
    list = str.split(” “);
    if(n!=list.length){
    System.out.println(“Invalid Input”);
    }else if(k==0){
    System.out.println(100);
    }
    else{
    for(int i=0;i<n;i++){
    arr[i] = Integer.parseInt(list[i]);
    }

    int p = 0;
    int E = 100;
    boolean cond = true;
    while(true){
    p = (p + k)%n;
    if(arr[p]==0){
    E= E-1;
    }else{
    E= E-3;
    }
    if(E<0){
    cond=false;
    break;
    }
    if(p==0){
    break;
    }
    }
    if(!cond){
    System.out.println("Not possible");
    }else{
    System.out.println(E);
    }
    }
    }
    }


  • Rudra

    import java.io.*;
    import java.math.*;
    import java.security.*;
    import java.text.*;
    import java.util.*;
    import java.util.concurrent.*;
    import java.util.regex.*;

    public class Solution {

    // Complete the jumpingOnClouds function below.
    static int jumpingOnClouds(int[] c, int k) {
    int energy =100;
    int i =0;
    do{
    if(c[i]==1){
    energy= energy-3;
    }
    else{
    energy=energy-1;
    }
    i=(i+k)%c.length;
    }while(i!=0);

    return energy;
    }

    private static final Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) throws IOException {
    BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(System.getenv(“OUTPUT_PATH”)));

    String[] nk = scanner.nextLine().split(” “);

    int n = Integer.parseInt(nk[0]);

    int k = Integer.parseInt(nk[1]);

    int[] c = new int[n];

    String[] cItems = scanner.nextLine().split(” “);
    scanner.skip(“(\r\n|[\n\r\u2028\u2029\u0085])?”);

    for (int i = 0; i < n; i++) {
    int cItem = Integer.parseInt(cItems[i]);
    c[i] = cItem;
    }

    int result = jumpingOnClouds(c, k);

    bufferedWriter.write(String.valueOf(result));
    bufferedWriter.newLine();

    bufferedWriter.close();

    scanner.close();
    }
    }