Toggle String Hackerearth Problem Solution – Coder In Me

You have been given a String S consisting of uppercase and lowercase English alphabets. You need to change the case of each alphabet in this String. That is, all the uppercase letters should be converted to lowercase and all the lowercase letters should be converted to uppercase. That is Toggle String. You need to then print the resultant String to output.

Input Format Of Toggle String

The first and only line of input contains the String S

Output Format
Print the resultant String on a single line.

1<=|S|<=100, where S denotes the length of string S.

Let Us  See Example Of  Toggle String –

Sample Input

Sample Output

How We Can Solve Toggle String Problem-

  • Firstly know about the ASCII value of capital alphabet and small alphabet to sort this problem.
  • Give the string S as input And check it character by character.
  • If  S[i] greater than and equal 65 AND less than and equal 90, Add 32 in S[i] to convert into lower case.
  • OTHERWISE subtract 32 from S[i] to convert lower case into upper case.
    HERE, i represents natural number.. 0,1,…… AND S[i] represents string with index.

let a string and check it with it’s index character by character.

S[0] = s this is not satisfy the our giving condition. So SUBTRACT 32 to the screen output as  S.

S[1] = H this is greater than 65 and less than 90. So ADD 32 to the screen output as h.




#include <stdio.h>

int main()
  char S[100]; /* string as character type
  int i;
  scanf("%s",S);  // Reading input from STDIN
     if(S[i] >= 65 && S[i] <= 90)
    S[i] = (char)(S[i] + 32);
    S[i] = (char)(S[i] - 32);
     printf("%s",S);  // Writing output to STDOUT
return 0;

For more Hackerearth problem solution click here

All rights reserved. No part of this Post may be copied, distributed, or transmitted in any form or by any means, without the prior written permission of the website admin, except in the case of brief quotations embodied in critical reviews and certain other noncommercial uses permitted by copyright law. For permission requests, write to the owner, addressed “Attention: Permissions Coordinator,” to the admin @coderinme

Leave a reply:

Your email address will not be published.