Write a program which finds the next-to-last word in a string.
Your program should accept as its first argument a path to a filename. Input example is the following
some line with text
Each line has more than one word.
Print the next-to-last word in the following way.
Write a program to determine the shortest repetition in a string.
A string is said to have period p if it can be formed by concatenating one or more repetitions of another string of length p. For example, the string “xyzxyzxyzxyz” has period 3, since it is formed by 4 repetitions of the string “xyz”. It also has periods 6 (two repetitions of “xyzxyz”) and 12 (one repetition of “xyzxyzxyzxyz”).
Your program should accept as its first argument a path to a filename. Each line will contain a string of up to 80 non-blank characters. E.g.
Print out the smallest period of the input string. E.g.
By starting at the top of the triangle and moving to adjacent numbers on the row below, the maximum total from top to bottom is 27.
4 6 8
0 7 1 5
5 + 9 + 6 + 7 = 27
Your program should accept as its first argument a path to a filename. Input example is the following:
4 6 8
0 7 1 5
You make also check full input file which will be used for your code evaluation.
The correct output is the maximum sum for the triangle. So for the given example the correct answer would be 27
A modified Kaprekar number is a positive whole number n with d digits, such that when we split its square into two pieces – a right hand piece r with d digits and a left hand piece l that contains the remaining d or d−1 digits, the sum of the pieces is equal to the original number (i.e. l + r = n).
Note: r may have leading zeros.
Here’s an explanation from Wikipedia about the ORIGINAL Kaprekar Number (spot the difference!): In mathematics, a Kaprekar number for a given base is a non-negative integer, the representation of whose square in that base can be split into two parts that add up to the original number again. For instance, 45 is a Kaprekar number, because 45² = 2025 and 20+25 = 45.
You are given the two positive integers p and q, where p is lower than q. Write a program to determine how many Kaprekar numbers are there in the range between p and q (both inclusive) and display them all.
There will be two lines of input: p, lowest value q, highest value
Output each Kaprekar number in the given range, space-separated on a single line. If no Kaprekar numbers exist in the given range, print INVALID RANGE.
1, 9, 45, 55, and 99 are the Kaprekar Numbers in the given range.