fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. bool isValid(string str, int n)
  4. {
  5.  
  6. if (!((str[0] >= 'a' && str[0] <= 'z')
  7. || (str[0] >= 'A' && str[0] <= 'Z')
  8. || str[0] == '_'))
  9. return false;
  10.  
  11.  
  12. for (int i = 1; i < str.length(); i++) {
  13. if (!((str[i] >= 'a' && str[i] <= 'z')
  14. || (str[i] >= 'A' && str[i] <= 'Z')
  15. || (str[i] >= '0' && str[i] <= '9')
  16. || str[i] == '_'))
  17. return false;
  18. }
  19.  
  20.  
  21. return true;
  22. }
  23.  
  24. int main()
  25. {
  26. string str = "geeks123";
  27. int n = str.length();
  28.  
  29. if (isValid(str, n))
  30. cout << "Valid";
  31. else
  32. cout << "Invalid";
  33.  
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Valid