Posts

Showing posts from July, 2017

TCS Code Vita 6 ( problem-B )

Problem : Concatenating primes If you like numbers, you may have been fascinated by prime numbers. Sometimes we obtain by concatenating two primes. For example, concatenating 2 and 3, we obtain the prime 23. The aim is to find all such distinct "concatenated primes" that could be obtained by concatenating primes ≤ a given integer N. Input Format: Integer N Output Format : M, the number of distinct primes that could be obtained by concatenating two primes ≤ N Constraints: N ≤ 70 Example 1 Input 10 Output 4   Explanations The primes ≤ 10 are 2, 3, 5, 7. These can be used to form the following concatenated numbers: 22, 23, 25, 27, 32, 33, 35, 37, 52, 53, 55, 57, 72, 73, 75, 77. Of these, there are four primes: 23 37 53 and 73. Hence the output is 4. Example 2 Input 20 Output 17 Explanation The prime numbers up to 20 are 2 3 5 7 11 13 17 and 19. Concatenating these two at a time in all possible ways, we get the following numbers: 22 23 25 27 211 213 217 219 32 33 35 3

Codechef Probem : NITIKA

Problem : Link: ( https://www.codechef.com/JULY17/problems/NITIKA ) Nitika was once reading a history book and wanted to analyze it. So she asked her brother to create a list of names of the various famous personalities in the book. Her brother gave Nitika the list. Nitika was furious when she saw the list. The names of the people were not properly formatted. She doesn't like this and would like to properly format it. A name can have at most three parts: first name, middle name and last name. It will have at least one part. The last name is always present. The rules of formatting a name are very simple: Only the first letter of each part of the name should be capital. All the parts of the name except the last part should be represented by only two characters. The first character should be the first letter of the part and should be capitalized. The second character should be ".". Let us look at some examples of formatting according to these rule

HackerRank Problem : Min Max Sum ( easy )

Problem :   ( Link :  Click here to visit this HackerRank problem page. ) Given five positive integers, find the minimum and maximum values that can be calculated by summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers. Input Format A single line of five space-separated integers. Constraints Each integer is in the inclusive range . Output Format Print two space-separated long integers denoting the respective minimum and maximum values that can be calculated by summing exactly four of the five integers. (The output can be greater than 32 bit integer.) Sample Input 1 2 3 4 5   Sample Output 10 14   Explanation Our initial numbers are , , , , and . We can calculate the following sums using four of the five integers: If we sum everything except , our sum is . If we sum everything except , our sum is . If we sum everything e

HackerRank Problem : Reverse and capitalise first alphabet of each word.

  Problem : ( Link : Click here to visit this problem on HackerRank. ) Reverse the words in a string and capitalize the first letter of each reversed word, preserving the capitalization in the original stri. For eg: "Hello World" would be transformed to "OlleH DlroW". Input : The first line of input would be the number of test cases followed by each string in a line. Output : Output should be the string with each word reversed and first letter of each reversed word capitalized. Each output string should be printed to a new line.   Sample Input Sample Output 1 Hello World OlleH DlroW ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Solution : ( in C++ ) #include   <iostream> #include   <string> #include   <algorithm> #include   <cctype> using   namespace std ; int main (