0% found this document useful (0 votes)
148 views10 pages

Input #1: Output

Download as docx, pdf, or txt
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 10

There is a jar full of candies for sale at a mall counter.

The jar has the capacity


N, that is JAR can contain maximum N Candies when a JAR is full. At any
point in time, JAR can have an M number of candies where M<=N. Candies are
served to the customers. JAR is never remaining empty as when the last K
candidates are left, JAR is refilled with new candidates in such a way that JAR
gets full.
Write the code to implement the above scenario. Display JAR at the counter
with the available number of candies.
Input should be the number of candies one customer orders at a point in time.
Update the JAR after every purchase and display JAR at the counter. The output
should give the number of candies sold and the updated number of candies in
the JAR. If the input is more than the number of candies in JAR, return
“INVALID INPUT”. 

Given,
N=10, Where N is the number of candies available, K<=5, Where K is the
number of minimum candies that must be inside JAR ever.

Example1: (N=10,K=<5)
Input #1:
3
Output :
Number of Candies Sold: 3
Number of Candies available:7

Input #2:
4
Given a pair of positive integers m and n (m < n; 0 < m < 999; 1 < n < = 999),
write a program to smartly affix zeroes, while printing the numbers
from m to n.

Example-1
Input
5 10
Expected output
05 06 07 08 09 10
Example-2
Input
9 100
Expected output
009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026
027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044
045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062
063 064 065 067 068 069 070 071 072 073 074 075 076 077 078 079 080 081
082 083 084 085 086 087 088 089 090 091 092 093 094 095 096 097 098 099
100

Example-3
Input
19
Problem statement:
It was one of the places, where people need to get their provisions only through
fair price (“ration”) shops. As the elder had domestic and official work to attend
to, their wards were asked to buy the items from these shops. Needless to say,
there was a long queue of boys and girls. To minimize the tedium of standing in
the serpentine queue, the kids were given mints. I went to the last boy in the
queue and asked him how many mints he has. He said that the number of mints
he has is one less than the sum of all the mints of kids standing before him in
the queue. So I went to the penultimate kid to know how many mints she has.

She said that if I add all the mints of kids before her and subtract one from it,
the result equals the mints she has. It seemed to be a uniform response from
everyone. So, I went to the boy at the head of the queue consoling myself that
he would not give the same response as others. He said, “I have four mints”.
Given the number of first kid’s mints (n) and the length (len) of the queue as
input, write a program to display the total number of mints with all the kids.
constraints:
2<n<10
1<len<20

Input#1:
42
Output:
7

Input#2:
14 4
Problem Statement:- Jaya invented a Time Machine and wants to test it by
time-traveling to visit Russia on the Day of Programmer (the 256thday of the
year) during a year in the inclusive range from 1700 to 2700. From 1700 to
1917 , Russia’s official calendar was the Julian Calendar since 1919 they used
the Gregorian calendar system. The transition from the Julian to Gregorian
calendar system occurred in 1918 , when the next day after 31 January was
February 14 . This means that in 1918, February 14 was the 32nd day of the
year in Russia. In both calendar systems, February is the only month with a
variable amount of days; it has 29 days during a leap year, and 28 days during
all other years. In the Julian calendar, leap years are divisible by 4 ; in the
Gregorian calendar, leap years are either of the following:

 Divisible by 400
 Divisible by 4 and not divisible by 100

Given a year, y, find the date of the 256th day of that year according to the
official Russian calendar during that year. Then print it in the format
dd.mm.yyyy, where dd is the two-digit day, mm is the two-digit month, and
yyyy is y.

For example, the given year is 1984.1984 is divisible by 4, so it is a leap year.


The 256 day of a leap year after 1918 is September 12, so the answer is
12.9.1984. 

Function Description

 Complete the programmerday function in the editor below. It should


return a string representing the date of the 256th day of the year given.
 programmerday has the following parameter(s):
o year: an integer 

Input Format

 A single integer denoting year y.

Output Format
 Print the full date of programmerday during year y in the format
dd.mm.yyyy, where dd is the two-digit day, mm is the two-digit month,
and yyyy is y.

Sample Input

           2017

Sample Output

           13.09.2017

Ques. Write a code to check whether no is prime or not. Condition use function


check() to find whether entered no is positive or negative ,if negative then enter
the no, And if yes pas no as a parameter to prime() and check whether no is
prime or not?

Question

1. The program will recieve 3 English words inputs from STDIN

1. These three words will be read one at a time, in three separate line
2. The first word should be changed like all vowels should be replaced by *
3. The second word should be changed like all consonants should be
replaced by @
4. The third word should be changed like all char should be converted to
upper case
5. Then concatenate the three words and print them

Other than these concatenated word, no other characters/string should or


message should be written to STDOUT

For example if you print how are you then output should be h*wa@eYOU.

You can assume that input of each word will not exceed more than 5 chars

Test Cases

Case 1
Input
 how
 are
 you

Expected Output : h*wa@eYOU

Case 2
Input

 how
 999
 you

Expected Output : h*w999YOU

String Pair
Problem Description
One person hands over the list of digits to Mr. String, But Mr. String
understands only strings. Within strings also he understands only vowels. Mr.
String needs your help to find the total number of pairs which add up to a
certain digit D.

The rules to calculate digit D are as follow

Take all digits and convert them into their textual representation

Next, sum up the number of vowels i.e. {a, e, i, o, u} from all textual
representation

This sum is digit D

Now, once digit D is known find out all unordered pairs of numbers in input
whose sum is equal to D. Refer example section for better understanding.

Constraints
1 <= N <= 100

1 <= value of each element in second line of input <= 100


Number 100, if and when it appears in input should be converted to textual
representation as hundred and not as one hundred. Hence number of vowels in
number 100 should be 2 and not 4

Input
First line contains an integer N which represents number of elements to be
processed as input

Second line contains N numbers separated by space

Output
Lower case representation of textual representation of number of pairs in input
that sum up to digit D

Note: – (If the count exceeds 100 print “greater 100”)

Time Limit
1

Examples

Example 1

Input

12345

Output

one

Explanation

1 -> one -> o, e

2 -> two -> o

3 -> three -> e, e


4 -> four -> o, u

5 -> five – > i, e

Thus, count of vowels in textual representation of numbers in input = {2 + 1 + 2


+ 2 + 2} = 9. Number 9 is the digit D referred to in section above.

Now from given list of number {1,2,3,4,5} -> find all pairs that sum up to 9.

Upon processing this we know that only a single unordered pair {4, 5} sum up
to 9. Hence the answer is 1. However, output specification requires you to print
textual representation of number 1 which is one. Hence output is one.

Note: – Pairs {4, 5} or {5, 4} both sum up to 9. But since we are asking to count
only unordered pair, the number of unordered pair is this combination is only
one.

Example 2

Input

742

Output

zero

Explanation

7 -> seven -> e, e

4 -> four -> o, u

2 -> two -> o

Thus, count of vowels in textual representation of numbers in input = {2 + 2 +


1} = 5. Number 5 is the digit D referred to in section above.

Since no pairs add up to 5, the answer is 0. Textual representation of 0 is zero.


Hence output is zero.

3 Palindrome
Problem Description
Given an input string word, split the string into exactly 3 palindromic
substrings.

Working from left to right, choose the smallest split for the first substring that
still allows the remaining word to be split into 2 palindromes.

Similarly, choose the smallest second palindromic substring that leaves a third
palindromic substring.

If there is no way to split the word into exactly three palindromic substrings,
print “”Impossible”” (without quotes). Every character of the string needs to be
consumed.

Cases not allowed –

After finding 3 palindromes using above instructions, if any character of the


original string remains unconsumed.

No character may be shared in forming 3 palindromes.


Constraints
1 <= the length of input sting <= 1000
Input
First line contains the input string consisting of characters between [a-z].
Output
Print 3 substrings one on each line.
Time Limit
1

Examples
Example 1

Input

nayannamantenet

Output

nayan

naman
tenet

Explanation

The original string can be split into 3 palindromes as mentioned in the output.

However, if the input was nayanamantenet, then the answer would be


“”Impossible””.

Example 2

Input

aaaaa

Output

aaa

Explanation

The other ways to split the given string into 3 palindromes are as follows –

[a, aaa, a], [aaa, a, a], [aa, aa, a], etc.

Since we want to minimize the length of the first palindromic substring using
left to right processing, the correct way to split is [a, a, aaa].

Example 3

Input

aaaabaaaa

Output

aaabaaa
a

Explanation

The other ways to split the given string into 3 palindromes are as follows –

[aaaa, b, aaaa], [aa, aabaa, aa], etc.

Since we want to minimize the length of the first palindromic substring using
left to right processing, the correct way to split is [a, aaabaaa, a].”

You might also like