Robert is given a string that ends with a character or a number. He has to check the length of the given string and append it to the end in such a way that if the original string ends with a number then the new string with the appended value must have the length of the string as the last two characters. If the string ends with a character then append the total length as the last character.
Also, the number to be appended must be a single positive digit. Write a code to implement the given scenario.
Input format
Input consists of a string
Output format
The output displays the single-digit value to be appended. If the value is more than one digit or no digit is to be appended, then print -1.
Sample testcases
Input 1 : abcdefghijklmnop1
Output 1 : 6
Question 2:
Hari is a civil engineer who is designing a fountain in a square shape with water sprinklers in the edges with n number of steps. He needs to draw a sketch of the fountain in the top view with the step number at the edges of the square.
Write a program to help him in printing the pattern with n number of steps.
Input format
Input is a positive integer describing the step levels of the fountain.
Output format
The output consists of the pattern of numbers as described in the question for n number of step levels.
Sample test cases
Input 1: 5
Output 1:
1 1 2 2 3 3 4 4 5 4 4 3 3 2 2 1 1
Question 3:
Caption Contest Exeter Caption Contest is a competition open to all writers worldwide. The entrants will have one day to compose and submit a caption that will be based on the theme posted on the competition page.
Robin, a creative writer had penned two captions for the contest but he unknowingly misplaced them. After searching long, he managed to locate his captions, but some letters in them have become unreadable. The captions were in two very old sheets of paper, each of which originally contained a string of lowercase English letters. The strings on both the sheets have equal lengths.
Robin would like to estimate the difference between these strings. Let's assume that the first string is named S1, and the second S2. The unreadable symbols are specified with the question mark symbol ?! The difference between the strings equals to the number of positions i, such that Sli is not equal to $21, where Sli and S2i denote the symbol at the ith position in S1 and 52, respectively.
Robin would like to know the minimal and the maximal difference between the two strings, if he changes all unreadable symbols to lowercase English letters. Robin is not an expertise in programming and so he needs your help solving this problem!
Input format:
The first line of the input contains a string S1. The second line of the input contains a string S2. Both strings consist of lowercase English letters and question marks in places where the symbols are unreadable.
Output format:
Output the minimal and the maximal difference between two given strings separated with a single space. Refer sample input and output for formatting specifications.
Sample testcases:-
Input 1:
a?c
??b
Ouptut :
1 3
Input 2:
???a
???a
Output:
0 3
Solution and suggestion would be welcome ! Looking for advice or feedback from someone with more expertise or experience. ♥