<p>We define the usage of capitals in a word to be right when one of the following cases holds:</p>

<ul>
	<li>All letters in this word are capitals, like <code>&quot;USA&quot;</code>.</li>
	<li>All letters in this word are not capitals, like <code>&quot;leetcode&quot;</code>.</li>
	<li>Only the first letter in this word is capital, like <code>&quot;Google&quot;</code>.</li>
</ul>

<p>Given a string <code>word</code>, return <code>true</code> if the usage of capitals in it is right.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> word = "USA"
<strong>Output:</strong> true
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> word = "FlaG"
<strong>Output:</strong> false
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= word.length &lt;= 100</code></li>
	<li><code>word</code> consists of lowercase and uppercase English letters.</li>
</ul>

class Solution {
public:
    bool isuppercase(string word){
        for(int i = 0; i<word.length(); i++){
            char one = word[i];
            if(one >= 'A' && one <= 'Z'){
                continue;
            }

            else
            {
                return false;
            }
        }

        return true;
    }

    bool islowercase(string word){
        for(int i = 0; i<word.length(); i++){
            char one = word[i];
            if(one >= 'a' && one <= 'z'){
                continue;
            }

            else
            {
                return false;
            }
        }

        return true;
    }
    
    bool checkfirstletter(string word){
        if(word[0] >= 'A' && word[0]<='Z'){
            for(int i = 1; i<word.length(); i++){
                if(word[i]>='a' && word[i]<='z'){
                    continue;
                }
                else
                {
                    return false;
                }
            }
        }

        return true;
    }
    
    bool detectCapitalUse(string word) {
       int n = word.size();
       if((word[0]>='A' && word[0]<='Z') && (word[n-1] >= 'a' && word[n-1]<='z')){
           return checkfirstletter(word);
       }
       for(int i = 0; i<word.length(); i++){
          if(word[i]>='A' && word[i]<='Z'){
            return isuppercase(word);
          }
          else if(word[i]>='a' && word[i]<='z'){
            return islowercase(word);
          }
       }

       return false;
    }
};
8000