Given an integer ‘k’ and a string ‘str’ consisting of characters from English alphabets. The task is to convert all lower case character to uppercase whose ASCII value is co-prime with k.
Input: str = “geeksforgeeks”, k = 4
‘f’ and ‘r’ are the only characters whose ASCII values aren’t co-prime with 4.
Input: str = “Ac”, k = 2
The only lower case character is ‘c’ and ASCII value of ‘c’ is 99 which is co-prime with 2.
- Iterate over all characters in the given string to check whether the current character is lowercase and if it’s ASCII value is co-prime with ‘k’
- To check for co-prime, check that if the gcd of the value with k is ‘1’ or not.
- If the above condition is satisfied then convert that lowercase alphabet to uppercase alphabet.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Check if lowercase and uppercase characters are in same order
- Remove uppercase, lowercase, special, numeric, and non-numeric characters from a String
- Check if a string contains uppercase, lowercase, special characters and numeric values
- Program to display all alphabets from A to Z in uppercase and lowercase both
- Minimum number of operations to move all uppercase characters before all lower case characters
- Count Uppercase, Lowercase, special character and numeric values
- Maximum distinct lowercase alphabets between two uppercase
- Find number of substrings of length k whose sum of ASCII value of characters is divisible by k
- Count pairs of characters in a string whose ASCII value difference is K
- Subsequences generated by including characters or ASCII value of characters of given string
- Convert Hexadecimal value String to ASCII value String
- Count characters in a string whose ASCII values are prime
- Replace every character of string by character whose ASCII value is K times more than it
- Sub-strings having exactly k characters that have ASCII value greater than p
- Convert the ASCII value sentence to its equivalent string
- Sub-string that contains all lowercase alphabets after performing the given operation
- Program to find the largest and smallest ASCII valued characters in a string
- Average of ASCII values of characters of a given string
- Program to find the product of ASCII values of characters in a string
- Find the sum of the ascii values of characters which are present at prime positions
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.