Created
April 23, 2019 02:22
-
-
Save luciocf/1b679e70fe2757d3f8c37a4edb6d8501 to your computer and use it in GitHub Desktop.
Noic - Iniciante - Semana 53 - Problema 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Noic - Iniciante - Semana 53 - Problema 1 | |
// O(n) | |
#include <bits/stdc++.h> | |
using namespace std; | |
int main(void) | |
{ | |
string s; | |
int pos_h, pos_e, pos_l1, pos_l2, pos_o; | |
pos_h = pos_e = pos_l1 = pos_l2 = pos_o = -1; // com -1 indicamos que a posição não foi encontrada ainda | |
cin >> s; | |
for (int i = 0; i < s.size(); i++) | |
{ | |
if (s[i] == 'h') pos_h = i; | |
else if (s[i] == 'e' && pos_h != -1) pos_e = i; | |
else if (s[i] == 'l' && pos_e != -1 && pos_l1 == -1) pos_l1 = i; | |
else if (s[i] == 'l' && pos_l1 != -1) pos_l2 = i; | |
else if (s[i] == 'o' && pos_l2 != -1) pos_o = i; | |
} | |
if (pos_h != -1 && pos_e != -1 && pos_l1 != -1 && pos_l2 != -1 && pos_o != -1) printf("SIM\n"); | |
else printf("NAO\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment