Questions
C++ [2] Write a program that prompts the user to enter a non-negative decimal number and...

C++

[2] Write a program that prompts the user to enter a non-negative decimal number and a base in the range 2 <= base <= 16. Write a function multibaseOutput() that displays the number in the specified base. The program terminates when the user enters a number of 0 and a base 0.

Run:
Enter a non-negative decimal number and base (2 <= B <= 16) or 0 0 to terminate: 155 16
    155 base 16 is 9B
Enter a non-negative decimal number and base (2 <= B <= 16) or 0 0 to terminate: 3553 8
    3553 base 8 is 6741
Enter a non-negative decimal number and base (2 <= B <= 16) or 0 0 to terminate: 0 0

In: Computer Science

2. Non-Local Strings For this question, a block is a sequence of 20 characters, where each...

2. Non-Local Strings

For this question, a block is a sequence of 20 characters, where each character is one of the 26 lowercase letters a-z. For example, these are blocks:

iwpiybhunrplsovrowyt
rpulxfsqrixjhrtjmcrr
fxfpwdhwgxtdaqtmxmlf
  1. How many different blocks are there?
  2. A block is squarefree if no character appears two times consecutively. The first and third example above are squarefree, but the second example is not because of the two consecutive occurrences of r. How many squarefree blocks are there?
  3. A block is non-local if the number of characters between any two occurrences of the same character is at least 2. The first example above is non-local. The second example is not, because there are two occurrences of r with no characters between them. The third example is not because there are two occurrences of m with only one character between them. How many non-local blocks are there?
  4. A block is k-non-local if the number of characters between any two occurrences of the same character is at least k. Write a formula for the number of k-non-local blocks that is valid for any k∈{0,…,20}.

Sanity check: The formula you get for 2.4 gives the answer to 2.2 when k=1 and gives the answer to 2.3 when k=2.

In: Math

Below is a school problem of mine. WHAT I KNOW AND HAVE DONE. i have three...

Below is a school problem of mine.
WHAT I KNOW AND HAVE DONE.
i have three variables for input
n for nunber of wnemies
k for fight capacity

an arraylist set to the size of n because it only needs to be as large as the number of enemies coming.

and x which is just the time stamps that will go into the arraylist.

i also have tHe array sorted from least to greatest because it doesnt matter what order they enter the times at but the time of the oppenets matters.

HELP NEEDED HERE.
I need help on how to handle the conditions of the program.
i know that it takes 1000secs to defeat an enemy. if an enemy appears and it is before 1000secs and less than an avengers capacity i need to add an avenger.
im having trouble on how to implent this into my program.


After many sacrifices and multiple time-heists, our beloved Avengers, finally managed to reverse

Thanos’ snap and bring everyone back to Earth. Now, only the final battle remains. Thanos’

army is huge and unpredictable, and the Avengers need to know when they will be attacking.

Luckily through Dr. Strange’s time travelling skills, he has seen the future and knows the arrival

time for each enemy. It is your job to find out how many avengers are needed to fight off

Thanos’ army.

Please make sure you are using an ArrayList<Integer> in this assignment. This is a requirement.
he timestamps are in chronological order. i.e. they will be entered by the user in increasing order.
To simplify this problem, we will make the following assumptions.

1) Every avenger can fight off equal number of enemies at once.

2) Each enemy takes 1000 seconds to defeat.

3) Multiple enemies may arrive at the same time.

Inputs

Your program will take the following inputs.

N: The total number of enemies to defeat.

K : the number of enemies each avenger can handle at once.

A list of N numbers, representing timestamps (in seconds).

Output

Your program should output the MINIMUM number of avengers needed to fight off Thanos’

army.

Sample Cases

Test Run 1

Input

Enter number of enemies (N) : 2

Enter fighting capacity of each avenger(K) : 1

Enter time of arrival for each enemy

300

1500

Output

1 avenger(s) are needed to fight off the army

Explanation: Avenger 1 starts fighting at t=300, defeats the first enemy at t=1300, can thus fight

the next enemy at t=1500. No additional avengers needed.

Test Run 2

Input

Enter number of enemies (N) : 3

Enter fighting capacity of each avenger(K) : 2

Enter time of arrival for each enemy

500

510

1499

Output

2 avenger(s) are needed to fight off the army

Explanation: Avenger 1 starts fighting at t=500, at t=510, 2nd enemy arrives, A1 can handle 2

enemies at once (see value of K), so still just 1 avenger needed. Next enemy arrives at t=499,

which is less than (500+1000), which means A1 is still fighting off 2 enemies at t=1499. Hence a

2nd avenger is needed, to deal with the last enemy. So minimum number = 2

Test Run 3

Input

Enter number of enemies (N) : 14

Enter fighting capacity of each avenger(K) : 3

Enter time of arrival for each enemy

100

200

345

980

1123

1242

1466

1777

1900

2000

2000

2001

2500

3000

Output

3 avenger(s) are needed to fight off the army

Explanation for Test Run 3 (A1 , A2 , A3 represents each avenger)

earliest

100

A1

earliest

100 200

A1 A1

earliest

100 200 345

A1 A1 A1

earliest

100 200 345 980

A1 A1 A1 A2

earliest

1123 200 345 980

A1 A1 A1 A2

earliest

1123 1242 345 980

A1 A1 A1 A2

earliest

1123 1242 1466 980

A1 A1 A1 A2

earliest

1123 1242 1466 1777

A1 A1 A1 A2

earliest

1123 1242 1466 1777 1900

A1 A1 A1 A2 A2

earliest

1123 1242 1466 1777 1900 2000

A1 A1 A1 A2 A2 A2

earliest

1123 1242 1466 1777 1900 2000 2000

A1 A1 A1 A2 A2 A2 A3

earliest

1123 1242 1466 1777 1900 2000 2000 2001

A1 A1 A1 A2 A2 A2 A3 A3

earliest

2500 1242 1466 1777 1900 2000 2000 2001

A1 A1 A1 A2 A2 A2 A3 A3

earliest

2500 3000 1466 1777 1900 2000 2000 2001

A1 A1 A1 A2 A2 A2 A3 A3

Approach

1) Each timestamp represents the time at which an enemy arrives.

2) You can represent the above data structure using an arraylist.

ArrayList<Integer> arr = new ArrayList<Integer>();

3) Every time you encounter a timestamp, you first check to see if 1000 secs has passed

since the earliest timestamp in your list. If yes, then the corresponding avenger has fought

off the earliest enemy in your list and has a ”slot open” to now fight the current enemy.

4) If 1000 secs have NOT passed since the earliest, then do one of the following

a. If the latest avenger is capable of simultaneously fighting more enemies than he is

currently fighting, then assign the current enemy to one of the “empty slots”

b. If all avengers are at full capacity, then introduce a new avenger, increment

minimum number of avengers needed by 1

In: Computer Science

The 2017 balance sheet of Kerber’s Tennis Shop, Inc., showed long-term debt of $2.7 million, and...

The 2017 balance sheet of Kerber’s Tennis Shop, Inc., showed long-term debt of $2.7 million, and the 2018 balance sheet showed long-term debt of $2.9 million. The 2018 income statement showed an interest expense of $95,000.

What was the firm’s cash flow to creditors during 2018?

In: Finance

Cutter Enterprises purchased equipment for $60,000 on January 1, 2018. The equipment is expected to have...

Cutter Enterprises purchased equipment for $60,000 on January 1, 2018. The equipment is expected to have a five-year life and a residual value of $3,600. Using the sum-of-the-years'-digits method, depreciation for 2018 and book value at December 31, 2018, would be: (Do not round depreciation rate per year)

In: Accounting

On November 1, 2018, Company borrowed $30,000 from a bank sign a 12-month, 6% interest rate...

On November 1, 2018, Company borrowed $30,000 from a bank sign a 12-month, 6% interest rate the first payment due on December 1, 2018. What should the company report on B/S, I/S and Statement of cashflow on Dec 31, 2018 and Dec 31, 2019?

In: Accounting

Tom and Betsy, who are married filing jointly, reported a standard deduction of $24,000 on their...

Tom and Betsy, who are married filing jointly, reported a standard deduction of $24,000 on their 2018 tax return. They paid $500 to the state for income taxes in 2018. In 2019, they received a $125 refund of state taxes paid in 2018. What is the amount that Tom and Betsy need to report on their 2019 tax return?

In: Accounting

In 2018, Grace - bought a used car for her personal use for RM50,000; - and...

In 2018, Grace
- bought a used car for her personal use for RM50,000;

- and spent RM8,000 on new car parts made in Malaysia.

For each of the two transactions above, explain how the components of GDP and the total GDP in 2018 are affected. What is the combined effect of these two transactions on Malaysian GDP in 2018?

In: Economics

The life spans of a species of fruit flies have a bell shaped distribution with a...

  1. The life spans of a species of fruit flies have a bell shaped distribution with a mean of 33 days and a standard deviation of 4 days.
  1. The life spans of three randomly selected tires are 34, 30, and 42 days. Find the z-score for these life-spans and specify if any of the life spans are unusual.
  2. The life spans of three fruit flies are 29, 41, and 25 days. Use the empirical rule to determine the percentile rank of each life span.
  3. If a sample of 40 fruit flies is studied, how many fruit flies would have a life span between 25 and 41 days according to Chebychev’s theorem.

In: Statistics and Probability

Barber and Odean, in their 2002 Journal of Finance paper entitled “Trading Is Hazardous to Your...

Barber and Odean, in their 2002 Journal of Finance paper entitled “Trading Is Hazardous to Your Wealth: The Common Stock Investment Performance of Individual Investors” state that:

“Our most dramatic empirical evidence supports the view that overconfidence leads to excessive trading. On one hand, there is very little difference in the gross performance of households that trade frequently (with monthly turnover in excess of 8.8 percent) and those that trade infrequently. In contrast, households that trade frequently earn a net annualized geometric mean return of 11.4 percent, and those that trade infrequently earn 18.5 percent.” Attempt to explain these findings using the behavioural finance theory.

In: Economics