Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
901 B
0
Indexable
Never
#include <iostream>
using namespace std;

int main() {
    string input;
    cin >> input;
  
    int n=0,e=0,i=0,g=0,h=0;
    int ans=-1;
    int horses=0;
    int num=input.size();
    for(int index=0;index<num;index++){
        switch(input[index]){
            case 'n':
                horses++;
                n++;
                break;
            case 'e':
                e++;
                break;
            case 'i':
                i++;
                break;
            case 'g':
                g++;
                break;
            case 'h':
                h++;
                horses--;
                break;
        }
        ans=max(ans,horses);
        if(n<e || e<i || i<g || g<h) {
            cout << "Invalid" << endl;
            return 0;
        }

    }
    if (horses != 0) {
      cout << "Invalid" << endl;
    } else {
      cout << ans;
    }
    return 0;
}