fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <cctype>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. bool A(const string& e) {
  10. size_t p1 = e.find('@');
  11. if (p1 == string::npos || e.rfind('@') != p1) {
  12. return false;
  13. }
  14. if (p1 == 0 || p1 == e.length() - 1) {
  15. return false;
  16. }
  17.  
  18. size_t p2 = e.find('.', p1);
  19. if (p2 == string::npos || p2 == p1 + 1 || p2 == e.length() - 1) {
  20. return false;
  21. }
  22.  
  23. for (char c : e) {
  24. if (c != '@' && c != '.') {
  25. if (!islower(c)) {
  26. return false;
  27. }
  28. }
  29. }
  30. return true;
  31. }
  32.  
  33.  
  34. bool B(const string& p) {
  35. if (p.length() < 8) {
  36. return false;
  37. }
  38.  
  39. bool l = false;
  40. bool u = false;
  41. bool d = false;
  42. bool s = false;
  43.  
  44. const string y = "!@#%&*_-.";
  45.  
  46. for (char c : p) {
  47. if (islower(c)) {
  48. l = true;
  49. } else if (isupper(c)) {
  50. u = true;
  51. } else if (isdigit(c)) {
  52. d = true;
  53. } else if (y.find(c) != string::npos) {
  54. s = true;
  55. }
  56.  
  57. if (l && u && d && s) {
  58. return true;
  59. }
  60. }
  61.  
  62. return l && u && d && s;
  63. }
  64.  
  65. int main() {
  66. string e, p;
  67.  
  68. if (!(cin >> e >> p)) {
  69. return 0;
  70. }
  71.  
  72. if (A(e) && B(p)) {
  73. cout << "Valid" << endl;
  74. } else {
  75. cout << "InValid" << endl;
  76. }
  77.  
  78. return 0;
  79. }
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
Standard output is empty