Computer Science, asked by meghanahulagur6, 3 months ago

given a string size N in one move you can change the case of the characters you need to find the number of moves
such that zero or more uppercase character are followed by zero or more lower case letter

Answers

Answered by sancitasaoo137
3

Explanation:

Take one string of any length and calculate its length.

Scan string character by character and keep checking the index .

If character in a index is in lower case, then subtract 32 to convert it in upper case, else add 32 to convert it in lower case

Print the final string.

// CPP program to Convert characters

// of a string to opposite case

#include <iostream>

using namespace std;

// Function to convert characters

// of a string to opposite case

void convertOpposite(string& str)

{

int ln = str.length();

// Conversion according to ASCII values

for (int i = 0; i < ln; i++) {

if (str[i] >= 'a' && str[i] <= 'z')

// Convert lowercase to uppercase

str[i] = str[i] - 32;

else if (str[i] >= 'A' && str[i] <= 'Z')

// Convert uppercase to lowercase

str[i] = str[i] + 32;

}

}

// Driver function

int main()

{

string str = "GeEkSfOrGeEkS";

// Calling the Function

convertOpposite(str);

cout << str;

return 0;

}

Output:

gEeKsFoRgEeKs

Time Complexity: O(n)

Note: This program can alternatively be done using C++ inbuilt functions – Character.toLowerCase(char) and Character.toUpperCase(char).

Approach 2: The problem can be solved using letter case toggling. Follow the below steps to solve the problem:

Similar questions