fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. int t;
  7. cin >> t;
  8. while(t--) {
  9. string s;
  10. cin >> s;
  11.  
  12. int maxDigit = 0;
  13. for(char c : s) {
  14. if(c - '0' > maxDigit) maxDigit = c - '0';
  15. }
  16.  
  17. // لو الرقم كله رقم واحد فقط
  18. if(s.size() == 1) {
  19. cout << 0 << endl;
  20. } else {
  21. int count = 0;
  22. bool found = false;
  23. // نبحث عن أول ظهور للـ maxDigit
  24. for(char c : s) {
  25. if(!found && (c - '0') == maxDigit) {
  26. found = true;
  27. } else {
  28. count++;
  29. }
  30. }
  31. cout << count << endl;
  32. }
  33. }
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5288KB
stdin
4
666
13700
102030
7
stdout
2
4
5
0