Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Case conversion problem solution

YASH PAL, 31 July 202413 February 2026
In this HackerEarth Case conversion problem solution, 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:
  1. ComputerHope
  2. FedEx
  3. WordPerfect
Note: In the camel case string, the first character may or may not be capitalized.
 
 
HackerEarth Case conversion problem solution

 

 

HackerEarth Case conversion problem solution.

def case_conversion():
t = int(raw_input())
for _ in xrange(t):
s = raw_input()
res = []
res.append(s[0].lower())
for i in s[1:]:
if i.isupper():
res.append('_')
res.append(i.lower())
else:
res.append(i)
print ''.join(res)

case_conversion()
 
 

Second solution

#include<bits/stdc++.h>

using namespace std;

int main() {
int t;
cin>>t;
assert(t>=1 && t<=100);
while(t--) {
string s; cin>>s;
int n=s.size();
assert(n>=1 && n<=100);
for(char c:s) {
assert(islower(c) || isupper(c));
}
for(int i=0;i<n;i++) {
if(isupper(s[i])) {
if(i>0) cout<<'_';
char c=s[i];
putchar(tolower(c));
}
else cout<<s[i];
}
cout<<endl;
}

return 0;
}
 
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes