Check if uppercase characters in a string are used correctly or not | C ++ program for the above approach ; Function to check if the character c is in lowercase or not ; Function to check if the character c is in uppercase or not ; Utility function to check if uppercase characters are used correctly or not ; Length of string ; If the first character is in lowercase ; Otherwise ; Check if all characters are in uppercase or not ; If all characters are in uppercase ; Check if all characters except the first are in lowercase ; Function to check if uppercase characters are used correctly or not ; Stores whether the use of uppercase characters are correct or not ; If correct ; Otherwise ; Driver Code ; Given string ; Function call to check if use of uppercase characters is correct or not
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isLower ( char c ) { return c >= ' a ' and c < = ' z ' ; } bool isUpper ( char c ) { return c >= ' A ' and c < = ' Z ' ; } bool detectUppercaseUseUtil ( string S ) { int N = S . size ( ) ; int i ; if ( isLower ( S [ 0 ] ) ) { i = 1 ; while ( S [ i ] && isLower ( S [ i ] ) ) ++ i ; return i == N ? true : false ; } else { i = 1 ; while ( S [ i ] && isUpper ( S [ i ] ) ) ++ i ; if ( i == N ) return true ; else if ( i > 1 ) return false ; while ( S [ i ] && isLower ( S [ i ] ) ) ++ i ; return i == N ? true : false ; } } void detectUppercaseUse ( string S ) { bool check = detectUppercaseUseUtil ( S ) ; if ( check ) cout << " Yes " ; else cout << " No " ; } int main ( ) { string S = " GeeKs " ; detectUppercaseUse ( S ) ; return 0 ; }