Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits\stdc++.h>
- using namespace std;
- int main()
- {
- int t;
- scanf("%d", &t);
- while(t--)
- {
- int n, i;
- scanf("%d", &n);
- string s;
- cin >> s;
- int cnt = 0;
- for(i = n - 1; i >= 0; i--)
- {
- cnt += (s[i] - '0');
- if(i - 1 != -1) if(s[i - 1] != '0') cnt++;
- }
- printf("%d\n", cnt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement