fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. int t;
  6. cin >> t;
  7.  
  8. while (t--)
  9. {
  10. string n;
  11. cin >> n;
  12. int sum = 0, n2 = 0, n3 = 0;
  13. for (int i = 0; i < n.size(); i++)
  14. {
  15. sum += n[i] - '0';
  16. if (n[i] == '2')
  17. n2++;
  18. if (n[i] == '3')
  19. n3++;
  20. }
  21. bool ok = 0;
  22. for (int i = 0; i <= n2; i++)
  23. {
  24. for (int j = 0; j <= n3; j++)
  25. {
  26. if (!((sum + i * 2 + j * 6) % 9))
  27. {
  28. ok = true;
  29. if (ok)
  30. break;
  31. }
  32. }
  33. if (ok)
  34. break;
  35. }
  36. if (ok)
  37. cout << "YES\n";
  38. else
  39. cout << "NO\n";
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
Standard output is empty