Switch to English?
Yes
Переключитись на українську?
Так
Переключиться на русскую?
Да
Przełączyć się na polską?
Tak
Post your project for free and start receiving proposals from freelancers within minutes after publication!

It is timely!!! Rewrite work codes from Java to Python

Translated11 USD

    1 proposal concealed
  • Vladislav V.
    21 December 2022, 9:52 |

    Добрий день. Прикріпіть будь ласка коди до опису завдання

  • Anya Stogar
    21 December 2022, 16:18 |

    import java.util.Scanner;

    import java.util.Arrays;


    public class a_planting_trees {

        public static void main(String[] args) {

            Scanner in = new Scanner(System.in);

            int length = in.nextInt();

            int minTime = 0;

            Integer treeArray[] = new Integer[length];



            for (int i = 0; i < length; i++) {

                treeArray[i] = in.nextInt();

            }

            Arrays.sort(treeArray);

            

            int day = 1;

            for (int i = length - 1; i >= 0; i--) {

                // System.out.println(day);

                if (day + treeArray[i] > minTime) {

                    minTime = day + treeArray[i];

                }

                day++;

            }

            // System.out.println(Arrays.toString(treeArray));

            System.out.println(minTime + 1);

        }

    }



    2

    import java.util.ArrayList;

    import java.util.List;

    import java.util.Scanner;



    public class g_platforms {

        public static void main(String[] args) {

            Scanner in = new Scanner(System.in);

            int platfNum = in.nextInt();

            int platfHeights[] = new int[platfNum];

            long wastedEnergy[] = new long[platfNum];

            // An array that stores info: Ypu come to platform j from arr[j]

            int whereFrom[] = new int[platfNum];

            whereFrom[0] = Integer.MIN_VALUE;

            // To store path(synamic because path cam be smaller)

            List<Integer> path = new ArrayList<Integer>();


            for (int i = 0; i < platfNum; i++) {

                platfHeights[i] = in.nextInt();

            }

            wastedEnergy[0] = 0;

            wastedEnergy[1] = Math.abs(platfHeights[1] - platfHeights[0]);

            

            long megaJump, normalJump;

            for (int i = 2; i < platfNum; i++) {

                megaJump = wastedEnergy[i-2] + 3 * Math.abs(platfHeights[i] - platfHeights[i-2]);

                normalJump = wastedEnergy[i-1] + Math.abs(platfHeights[i] - platfHeights[i-1]);


                if (megaJump < normalJump) {

                    wastedEnergy[i] = megaJump;

                    whereFrom[i] = i - 2;

                } else {

                    wastedEnergy[i] = normalJump;

                    whereFrom[i] = i - 1;

                }

            }

            // We start getting the path len and path itself, start by default from last elem.

            int fromIdx = platfNum - 1;

            path.add(fromIdx + 1);

            int pathPlatfAmount = 1;

            while (whereFrom[fromIdx] != Integer.MIN_VALUE) {

                fromIdx = whereFrom[fromIdx];

                pathPlatfAmount++;

                path.add(fromIdx + 1);

            }

            // Results

            System.out.println(wastedEnergy[platfNum - 1]);

            System.out.println(pathPlatfAmount);

            for (int i = path.size() - 1; i >= 0; i--) {

                System.out.print(path.get(i) + " ");

            }

        }

    }


    3

    import java.util.Arrays;

    import java.util.Scanner;



    public class ICandyStore {

        public static void main(String[] args) {

            Scanner in = new Scanner(System.in);


            // Main Loop

            while (true) {

                int candyNum = in.nextInt();

                int totalMoney = (int)(in.nextDouble() * 100);

                // the ONLY Break Case

                if (candyNum == 0) {

                    break;

                }


                int calories[] = new int[candyNum];

                int cost[] = new int[candyNum];

                // Input management

                for (int i = 0; i < candyNum; i++) {

                    calories[i] = in.nextInt();

                    cost[i] = (int)(in.nextDouble() * 100);

                }

                int caloriesForPrices[] = new int[totalMoney + 1];


                for (int i = 0; i < candyNum; i++) {

                    for (int j = cost[i]; j < totalMoney + 1; j++) {

                        int caloriesForPrice = caloriesForPrices[j - cost[i]] + calories[i];

                        if (caloriesForPrice > caloriesForPrices[j]) {

                            caloriesForPrices[j] = caloriesForPrice;

                        }

                    }

                }   

                System.out.println(caloriesForPrices[totalMoney]);

            }


        }

    }


    line = input().split()

    width = int(line[0])

    l = int(line[1])

    river = input().split()

    for i in range(len(river)):

        river[i] = int(river[i])

    sum = 0

    for i in range(l):

        sum += river[i]

        i+=1

    minim = sum

    for i in range(l, width-1):

        sum = sum - river[i-l] + river[i]

        minim = min(minim, sum)

    print(minim)

  • Andrii Kolomoiets
    21 December 2022, 9:52 |

    Можна глянути на код ?

  • Anya Stogar
    21 December 2022, 16:18 |

    import java.util.Scanner;

    import java.util.Arrays;


    public class a_planting_trees {

        public static void main(String[] args) {

            Scanner in = new Scanner(System.in);

            int length = in.nextInt();

            int minTime = 0;

            Integer treeArray[] = new Integer[length];



            for (int i = 0; i < length; i++) {

                treeArray[i] = in.nextInt();

            }

            Arrays.sort(treeArray);

            

            int day = 1;

            for (int i = length - 1; i >= 0; i--) {

                // System.out.println(day);

                if (day + treeArray[i] > minTime) {

                    minTime = day + treeArray[i];

                }

                day++;

            }

            // System.out.println(Arrays.toString(treeArray));

            System.out.println(minTime + 1);

        }

    }



    2

    import java.util.ArrayList;

    import java.util.List;

    import java.util.Scanner;



    public class g_platforms {

        public static void main(String[] args) {

            Scanner in = new Scanner(System.in);

            int platfNum = in.nextInt();

            int platfHeights[] = new int[platfNum];

            long wastedEnergy[] = new long[platfNum];

            // An array that stores info: Ypu come to platform j from arr[j]

            int whereFrom[] = new int[platfNum];

            whereFrom[0] = Integer.MIN_VALUE;

            // To store path(synamic because path cam be smaller)

            List<Integer> path = new ArrayList<Integer>();


            for (int i = 0; i < platfNum; i++) {

                platfHeights[i] = in.nextInt();

            }

            wastedEnergy[0] = 0;

            wastedEnergy[1] = Math.abs(platfHeights[1] - platfHeights[0]);

            

            long megaJump, normalJump;

            for (int i = 2; i < platfNum; i++) {

                megaJump = wastedEnergy[i-2] + 3 * Math.abs(platfHeights[i] - platfHeights[i-2]);

                normalJump = wastedEnergy[i-1] + Math.abs(platfHeights[i] - platfHeights[i-1]);


                if (megaJump < normalJump) {

                    wastedEnergy[i] = megaJump;

                    whereFrom[i] = i - 2;

                } else {

                    wastedEnergy[i] = normalJump;

                    whereFrom[i] = i - 1;

                }

            }

            // We start getting the path len and path itself, start by default from last elem.

            int fromIdx = platfNum - 1;

            path.add(fromIdx + 1);

            int pathPlatfAmount = 1;

            while (whereFrom[fromIdx] != Integer.MIN_VALUE) {

                fromIdx = whereFrom[fromIdx];

                pathPlatfAmount++;

                path.add(fromIdx + 1);

            }

            // Results

            System.out.println(wastedEnergy[platfNum - 1]);

            System.out.println(pathPlatfAmount);

            for (int i = path.size() - 1; i >= 0; i--) {

                System.out.print(path.get(i) + " ");

            }

        }

    }


    3

    import java.util.Arrays;

    import java.util.Scanner;



    public class ICandyStore {

        public static void main(String[] args) {

            Scanner in = new Scanner(System.in);


            // Main Loop

            while (true) {

                int candyNum = in.nextInt();

                int totalMoney = (int)(in.nextDouble() * 100);

                // the ONLY Break Case

                if (candyNum == 0) {

                    break;

                }


                int calories[] = new int[candyNum];

                int cost[] = new int[candyNum];

                // Input management

                for (int i = 0; i < candyNum; i++) {

                    calories[i] = in.nextInt();

                    cost[i] = (int)(in.nextDouble() * 100);

                }

                int caloriesForPrices[] = new int[totalMoney + 1];


                for (int i = 0; i < candyNum; i++) {

                    for (int j = cost[i]; j < totalMoney + 1; j++) {

                        int caloriesForPrice = caloriesForPrices[j - cost[i]] + calories[i];

                        if (caloriesForPrice > caloriesForPrices[j]) {

                            caloriesForPrices[j] = caloriesForPrice;

                        }

                    }

                }   

                System.out.println(caloriesForPrices[totalMoney]);

            }


        }

    }


    line = input().split()

    width = int(line[0])

    l = int(line[1])

    river = input().split()

    for i in range(len(river)):

        river[i] = int(river[i])

    sum = 0

    for i in range(l):

        sum += river[i]

        i+=1

    minim = sum

    for i in range(l, width-1):

        sum = sum - river[i-l] + river[i]

        minim = min(minim, sum)

    print(minim)

Current freelance projects in the category Java

Development of an Android application player for the online TV service

607 USD

We need an Android developer to create a native Android application for an online TV service. Two versions are planned: for mobile devices: smartphones and tablets; for Android TV / Android STB: set-top boxes. Estimated timeline: up to 3 months. Estimated budget: 150,000…

JavaApp Development for Android ∙ 1 month 2 days back ∙ 32 proposals

Client
Anya Stogar
Ukraine Boyarka  3  0
Project published
3 years back
80 views