Programming & Computer Science Answers

C++ 9913
Python 5288
Java | JSP | JSF 3611
C 1680
C# 1362
Computer Networks 989
Algorithms 652
Databases | SQL | Oracle | MS Access 641
HTML/JavaScript Web Application 588
Other 537
Visual Basic 358
Assembler 209
Software Engineering 202
AJAX | JavaScript | HTML | PHP 166
MatLAB 150
MatLAB | Mathematica | MathCAD | Maple 124
Action Script | Flash | Flex | ColdFusion 112
UNIX/Linux Programming 89
Web Development 73
Excel 36
ASP | ASP.NET 23
Delphi | Pascal 21
Perl 16
Prolog 9
Functional Programming 9
MathCAD 5
Wolfram Mathematica 4
WPF 4
Ruby | Ruby on Rails 3
NodeJS Web Application 2

Questions answered by Experts: 26 876

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

During the exam she have to go into the magic room N times. Initially there are X magic items in the room. Before each visit she can use magic to decrease the number of magic items in the room. For each item she spends 1 mana point to destroy it. After each visit the number of magic items increases by 2 times. She can't go into room if there are more than L magic items in it. What minimum mana points does Kate need to pass the exam?

You need to solve this problem for several test cases.

INPUT

The first line of input contains single integer T (1≤T≤105) - a number of test cases.

Then follow T lines. The i-th of these lines contains three integers Xi, Li and Ni (0≤Xi,Li,Ni≤1018).

OUTPUT

Print T lines.

The i-th of them should contain single integer - minimum number of mana points needed to pass the exam in the i-th test case.

Sample Input

2
2 5 3
6 5 0

Sample Output

1
0

Given the schema:

Pizzas (

pizza TEXT,

PRI KEY (pizza)

);

Restaurants (

rname TEXT,

area TEXT not null,

PRI KEY (rname)

);

Customers (

cname TEXT,

area TEXT not null,

PRI KEY (cname)

);

Sells (

rname TEXT,

pizza TEXT,

price INTEGER not null,

PRI KEY (rname,pizza),

FK (rname) REF Restaurants (rname),

FK (pizza) REF Pizzas (pizza)

);

Likes (

cname TEXT,

pizza TEXT,

PRI KEY (cname,pizza),

FK (cname) REF Customers (cname),

FK (pizza) REF Pizzas (pizza)

);


A customer C is happy if for each pizza P that C likes, there are at least two restaurants, which are located in the same area as C, that sells P.

E.g. if Alice likes only pizzas P1 and P2, then Alice will be happy if

(1) restaurants RA and RB both sell P1;

(2) restaurants RC and RD both sell P2; and

(3) restaurants RA, RB, RC and RD are all located in the same area as Alice.

It doesn't matter whether {RA,RB} and {RC,RD} are the same or different set of restaurants.

Find all happy customers(cname). Exclude customers who do not like any pizza.



Create a Python dictionary that returns a list of values for each key. The key can be whatever type you want.


Design the dictionary so that it could be useful for something meaningful to you. Create at least three different items in it. Invent the dictionary yourself. Do not copy the design or items from some other source.



def invert_dict(d):

inverse = dict()

for key in d:

val = d[key]

if val not in inverse:

inverse[val] = [key]

else:

inverse[val].append(key)

return inverse


Modify this function so that it can invert your dictionary. In particular, the function will need to turn each of the list items into separate keys in the inverted dictionary.


Run your modified invert_dict function on your dictionary. Print the original dictionary and the inverted one.


Include your Python program and the output in your Learning Journal submission.


Describe what is useful about your dictionary. Then describe whether the inverted dictionary is useful or meaningful, and why.



alphabet = "abcdefghijklmnopqrstuvwxyz"


test_dups = ["zzz","dog","bookkeeper","subdermatoglyphic","subdermatoglyphics"]


test_miss = ["zzz","subdermatoglyphic","the quick brown fox jumps over the lazy dog"]


def histogram(s):

d = dict()

for c in s:

if c not in d:

d[c] = 1

else:

d[c] += 1

return d

Part 1


Write a function called has_duplicates that takes a string parameter and returns True if the string has any repeated characters. Otherwise, it should return False.


aaa has duplicates

abc has no duplicates


Part 2

Write a loop over the strings in list test_miss and call missing_letters with each string. Print a line for each string listing the missing letters. For example, for the string "aaa", the output should be the following.


aaa is missing letters bcdefghijklmnopqrstuvwxyz


abcdefghijklmnopqrstuvwxyz uses all these letters




Describe how tuples can be useful with loops over lists and dictionaries, and give Python code examples. Create your own code examples. Do not copy them from the textbook or any other source.


Your descriptions and examples should include the following: the zip function, the enumerate function, and the items method.


Unite Family


Given three objects

father, mother, and child, write a JS program to concatenate all the objects into the family object using the spread operator.Input

  • The first line of input contains an object father
  • The second line of input contains an object mother
  • The third line of input contains an object child

Output

  • The output should be a single line string with the appropriate statement as shown in sample outputs

Constraints

  • Keys of the objects should be given in quotes


Sample Input

{'surname' : 'Jones', 'city': 'Los Angeles'}

{'dish': 'puddings'}

{'pet': 'Peter'}


Sample Output

Mr and Mrs Jones went to a picnic in Los Angeles with a boy and a pet Peter. Mrs Jones made a special dish "puddings"




Manufacturing Date


Given a expiry date

expiryDate and number of months before expiry monthsBeforeExpiry of a product, write a JS program to find the manufacturing date.
Input

  • The first line of input contains a date string expiryDate
  • The second line of input contains a number monthsBeforeExpiry

Output

  • The output should be a single line containing the manufacturing date of the product


Sample Input 1

2020-01-21

8


Sample Output 1

21-5-2019


Sample Input 2

2021-11-12

2


Sample Output 2

12-9-2021




Hotel Bill

A Hotel is offering discounts to its customers.

Given charge per day

dayCharge based on category and numbers of days customer stayed days as inputs, write a JS arrow function to return the total bill with the discount.


Quick Tip

  • The formula for bill is,
  • bill = dayCharge * days
  • The formula to calculate the discounted bill,
  • bill - (bill * discount) / 100

Apply discounts on the following basis,

  • 5%, if the customer stays more than 2 days
  • 15%, if the customer stays more than 5 days

Input

  • The first line of input contains a number dayCharge
  • The second line of input contains a number days

Output

  • The output should be a single line containing the total bill with the discount


Sample Input 1

200

3


Sample Output 1

570


Sample Input 2

180

1


Sample Output 2

180




When developing a new software we should take into account how to create a speci±c

"Look and Feel" per customer, What are the advantages of using Java GUI ?



• Consider a bit streaming scenario for a video where the following values apply:

– The buffer size is 1 MiB

– The low watermark is set at 100KiB

– The high watermark is set at 900KiB

– The incoming data rate is 1Mbps

– The video display rate is 300 Kbps

Assume that the video is playing and that the buffer content has dropped to the low-water mark. The media player sets the controls for data input to begin again.

– Calculate the amount of data that will be input in two seconds to the buffer and the amount of data that will be removed from the buffer in the same period of time.

– Repeat the calculation for 4,6,8,10,12 seconds.

– From this data estimate when the buffer will have filled up to the high water mark.

– Assuming that the incoming transmission is halted at this time, calculate how long it will be before the buffer content has again fallen to the low-water mark level.


LATEST TUTORIALS
APPROVED BY CLIENTS