Last Updated: 8 Jan, 2022

Convert To Lower Case

Easy
Asked in companies
Livekeeping (An IndiaMART Company)AmazonGoogle inc

Problem statement

You are given a string ‘str’, your task is to convert all the characters of the string into lowercase letters.

For example:
You are given, ‘str’ = ‘AbcdEfgh’, in this string if you convert all the characters into lowercase, the string will be ‘abcdefgg’. Hence it is the answer.
Input Format:
The first line of input contains a single integer ‘T’, representing the number of test cases.

The first line of each test case contains a string ‘str’ representing the given string.
Output Format:
For each test case, print a single string representing the given string with all characters in lower case.

Print a separate line for each test case.
Constraints:
1 <= T <=  10
1 <= |str| <= 10^4

‘str’ will contain upper and lower case characters of the English alphabet.
 Time Limit: 1 sec.
Note :
You do not need to print anything. It has already been taken care of. Just implement the given function. 
Sample Input 1:
2
AbcdEfgh
AAAAb

Approaches

01 Approach

 

In this approach, we will iterate over the entire string and if we find any character that is in upper case, we can convert it into the lowercase version of itself.

Note: below, ASC(ch) means ASCII value of the character ‘ch’.

 

Algorithm:

  • Initialise an empty string ‘resultString’
  • Iterate ch through ‘str
    • If ch is an upper case character
      • Add ASC(ch) + ASC(‘a’) - ASC(‘A’) converted to a character to ‘resultString’
    • Otherwise, add ch to ‘resultString’
  • Return the ‘resultString’