fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // Introduc variabilele a, b, c şi x;
  6. int a, b, c, x;
  7. // Citesc a, b, c, x;
  8. cin >> a >> b >> c >> x;
  9. int x_copy = 0;
  10. int c_copy = x;
  11.  
  12. if (c == x % 10) { // verificam "c"
  13. // Introduc variabila “cnt” sa numar cifrele;
  14. int cnt = 0;
  15. // parcurg x;
  16.  
  17. while (x > 0) {
  18. ++cnt;
  19. x_copy = x; // identific "b" introducand o variabila copie a lui x
  20. //pentru a mentine penultima valoare a lui x
  21. x /= 10;
  22. }
  23. if (c != c_copy % 10 || a != cnt || b != x_copy) cout <<"NU";
  24. if (b == x_copy && a == cnt)
  25. // verificam a si b
  26. cout << "DA";
  27. }
  28. return 0;
  29. }
  30.  
  31. /* Teste:
  32.  
  33. Valori minime
  34.  
  35. 3 1 2 102 -> DA
  36.  
  37. 1 3 2 123 -> NU
  38.  
  39. Valori maxime
  40.  
  41. 9 9 9 900000009 -> DA
  42.  
  43. 9 9 9 90000009 -> NU
  44.  
  45. 9 8 7 987654321 -> NU
  46.  
  47. Numere cu toate cifrele egale
  48.  
  49. 4 4 4 4444 -> DA
  50.  
  51. 7 7 7 7777777 -> DA
  52.  
  53. 8 8 8 888888 -> NU
  54.  
  55. Numere cu toate cifrele distincte
  56.  
  57. 4 4 1 4321 -> DA
  58.  
  59. 7 5 1 7451 -> NU
  60.  
  61.  
  62.  
  63. Numere cu doua cifre identice
  64.  
  65. 4 8 8 8458 -> DA
  66.  
  67. 5 5 6 59796 -> DA
  68.  
  69. Numere cu trei cifre identice
  70.  
  71. 3 3 3 333 -> DA
  72.  
  73. 4 6 8 6888 -> DA */
Success #stdin #stdout 0s 5308KB
stdin
3 1 2 102
stdout
DA