Advertisement
BojidarDosev

egn

Dec 20th, 2023 (edited)
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. bool isValidEGN(const std::string& egn)
  6. {
  7. //egn digs
  8. int x1 = egn[0] - '0';
  9. int x2 = egn[1] - '0';
  10. int x3 = egn[2] - '0';
  11. int x4 = egn[3] - '0';
  12. int x5 = egn[4] - '0';
  13. int x6 = egn[5] - '0';
  14. int x7 = egn[6] - '0';
  15. int x8 = egn[7] - '0';
  16. int x9 = egn[8] - '0';
  17. int x10 = egn[9] - '0';
  18. //y/m/d
  19. int year = std::stoi(egn.substr(0, 2));
  20. int month = std::stoi(egn.substr(2, 2));
  21. int day = std::stoi(egn.substr(4, 2));
  22. if (year < 10)
  23. {
  24. month += 20;
  25. }
  26. else if (year >= 100)
  27. {
  28. month += 40;
  29. }
  30. //egn check
  31. if (month < 1 || month > 12 || day < 1 || day > 31)
  32. {
  33. return 1;
  34. }
  35. int sum = 2 * x1 + 4 * x2 + 8 * x3 + 5 * x4 + 10 * x5 + 9 * x6 + 7 * x7 + 3 * x8 + 6 * x9;
  36. int remainder = sum % 11;
  37. if (remainder == 10)
  38. {
  39. remainder = 0;
  40. }
  41. if (remainder != x10)
  42. {
  43. return 1;
  44. }
  45. return 0;
  46. }
  47.  
  48. int main()
  49. {
  50. string egn;
  51. // Input egn
  52. cin >>egn;
  53. if (egn.length() != 10)
  54. {
  55. cout << "Invalid input data!" <<endl;
  56. return 0;
  57.  
  58. }
  59.  
  60. if (isValidEGN(egn))
  61. {
  62. cout<< 0;
  63. }
  64. else
  65. {
  66. cout<< 1;
  67. }
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement