From b6380057ea4bc18cc0f34285d9ccd274bd0b7932 Mon Sep 17 00:00:00 2001 From: anushkasinghal11 Date: Wed, 23 Dec 2020 19:53:20 +0530 Subject: [PATCH] manasa and stones --- .../Manasa and Stones/solution.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Algorithms/Implementation/Manasa and Stones/solution.java diff --git a/Algorithms/Implementation/Manasa and Stones/solution.java b/Algorithms/Implementation/Manasa and Stones/solution.java new file mode 100644 index 00000000..533c634c --- /dev/null +++ b/Algorithms/Implementation/Manasa and Stones/solution.java @@ -0,0 +1,45 @@ +import java.io.*; +import java.util.*; + +public class solution { + + public static void main(String[] args) { + /* + * Enter your code here. Read input from STDIN. Print output to STDOUT. Your + * class should be named Solution. + */ + Scanner input = new Scanner(System.in); + int T = input.nextInt(); + + for (int i = 0; i < T; i++) { + int n = input.nextInt() - 1;// Minus 1 to account for 0 starting stone + int a = input.nextInt(); + int b = input.nextInt(); + + // Edge case where no iterations are required + if (a == b) { + System.out.println(a * n + " "); + continue; + } + + // make sure a is our min + if (a > b) { + int temp = a; + a = b; + b = temp; + } + + int min = a * n; + int max = b * n; + + // We only need to increment by difference because there are only two stones to + // choose from each time + for (int finalSteps = min; finalSteps <= max; finalSteps += (b - a)) { + System.out.print(finalSteps + " "); + } + + System.out.println(); + + } + } +}