fork download
  1. #include <iostream>
  2. #include<string>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7. string s;
  8.  
  9. int k;
  10.  
  11. cin >> s >> k;
  12.  
  13. int n = s.length();
  14.  
  15. int ans = 0;
  16.  
  17. for(int i=n-1;i>=0 && k>0;i--)
  18. {
  19. if(s[i] == '0') {
  20. k--;
  21. }
  22. else {
  23. ans++;
  24. }
  25. }
  26.  
  27. if(k==0)
  28. {
  29. cout<<ans<<endl;
  30. } else cout<<n-1<<endl;
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 16064KB
stdin
10203049 2
stdout
3