Advertisement
Promi_38

cf 1573A

Sep 29th, 2021
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.39 KB | None | 0 0
  1. #include<bits\stdc++.h>  
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int t;
  8.     scanf("%d", &t);
  9.    
  10.     while(t--)
  11.     {
  12.         int n, i;
  13.         scanf("%d", &n);
  14.        
  15.         string s;
  16.         cin >> s;
  17.        
  18.         int cnt = 0;
  19.         for(i = n - 1; i >= 0; i--)
  20.         {
  21.             cnt += (s[i] - '0');
  22.             if(i - 1 != -1) if(s[i - 1] != '0') cnt++;
  23.         }
  24.        
  25.         printf("%d\n", cnt);
  26.     }
  27.    
  28. }
  29.  
  30.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement