Lilah has a string,
s, of lowercase English letters that she repeated infinitely many times.
Given an integer,
n, find and print the number of letter
a‘s in the first letters of Lilah’s infinite string.
The first line contains a single string,
The second line contains an integer,
25% of the test cases,
n <= 10^6
Print a single integer denoting the number of letter a’s in the first letters of the infinite string created by repeating infinitely many times.
Sample Input 0
Sample Output 0
n = 10 letters of the infinite string are
abaabaabaa. Because there are 7
a‘s, we print on a new line.
Sample Input 1
Sample Output 1
Because all of the first
n=1000000000000 letters of the infinite string are a, we print 1000000000000 on a new line.
BogoSort is a moderately well-known algorithm to sort a list. Here’s how it works:
- Put the elements of the list in a random order.
- Check if the list is sorted. If not, start over.
BogoSort has an average running time of O((n+1)!), which is not very good. It is also the rare algorithm which has NO worst-case running time; if the input has at least two elements, it is possible for the algorithm to run for any amount of time.
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.