Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Code is in Java Make sure input is from in2.txt (2) Get the Pounamu Stone! Moana wants to get the pounamu stone of the goddess

Code is in Java

Make sure input is from in2.txt

image text in transcribed

image text in transcribed

(2) Get the Pounamu Stone! Moana wants to get the pounamu stone of the goddess of the ocean Te Fiti, which is once stolen by the demigod Maui. A volcanic demon, Teka has the stone. Teka is very greedy and has a special bag, into which he can add one gold coin at a time or can remove the last gold coin he added. Teka will sleep, once he will have enough number of gold coins' worth amount X. To help Moana, her grandmother has given a bag to Moana with N gold coins each having worth Ai where i range from 1sisN. Moana can remove one gold coin at a time and she can remove the coins in order in which they were added to the Grandmother has also given her a set of instructions which contains two types of strings 1) "Take" (without quotes): It means Moana will remove ith coin from her bag and throw it towards Teka and Teka will add it in his bag, where i will start from 1 and go up to N 2) "Remove" (without quotes): it means Teka will remove the last coin he added in his bag. Once the worth of the coins in Teka's bag becomes equal to X, Teka will go to sleep. To report to grandmother, Moana wants to know the number of coins in Teka's bag, the first time their worth becomes equal to X. Help Moana to solve the problem and print the required number of coins. If the required condition doesn't occur print "-1" (without quotes). Input Take input from a file named in2.txt. The first line consists of the number of test cases. The first line of each test case consists of one integer N denoting the number of gold coins in Moana's Bag. Second line contains N space separated integers, denoting the worth of gold coins in the order in which they were added to Moana's bag. Third line contains 2 space separated integers Q and X, denoting the number of instructions and the value of X respectively. In next Q lines, each line contains one string either "Take" (without quotes) or "Remove" (without quotes) Output In one line, print the number of coins in the Teka's bag, the first time their worth becomes equal to X Constraints 1SNS104 1sA[i]s104 1sQs105 1SXs107

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

IBM Db2 11 1 Certification Guide Explore Techniques To Master Database Programming And Administration Tasks In IBM Db2

Authors: Mohankumar Saraswatipura ,Robert Collins

1st Edition

1788626915, 978-1788626910

More Books

Students also viewed these Databases questions

Question

please dont use chat gpt AI 9 2 0 .

Answered: 1 week ago