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. You need to then print the resultant String to output.
Example:
Input: s = "abcdE"
Output: ABCDe
Approach
C++
#include <bits/stdc++.h>using namespace std;string toggleString(string s){for (int i = 0; i < s.size(); i++){if (s[i] >= 'A' && s[i] <= 'Z')s[i] = s[i] + 32;elses[i] = s[i] - 32;}return s;}int main(){string s = "abcdE";cout << toggleString(s) << "\n";return 0;}
No comments:
Post a Comment