Case conversion

3.5

30 votes
Basic Programming, Easy, String Manipulation
Problem

You are given a string S in the camel case format. Your task is to convert this string into the snake case format.

Examples of the camel case strings are as follows:

  • ComputerHope
  • FedEx
  • WordPerfect

Note: In the camel case string, the first character may or may not be capitalized.

Examples of the snake case strings are as follows:

  • computer_hope
  • fed_ex
  • word_perfect

Input format

  • First line: T denotes the number of test cases
  • Next T lines: String S

Output format
For each test case, print the snake case format of the given camel case in the string S in a new line.

Constraints

1T100

1|S|100, where |S| indicates the length of string S

String S is made of lower and upper case English alphabets

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

First 3 test cases are from the statement itself.
In the fourth test case i.e. random, there's no uppercase letter in the string, so no need to add underscore anywhere. Hence the output is also random.
Fifth case is similar to second test valuecase.
In sixth test case, there are continuous uppercase characters. We add underscore before each of them. This is not really the snake case conversion or so to speak but for now we are OK with that.

Editor Image

?