Advertisement
Ankit_132

E

Feb 20th, 2024
836
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. #define pb push_back
  4. #define ff first
  5. #define ss second
  6. const int N=2e3+7;
  7. const int mod=1e9+7;
  8. using namespace std;  
  9.  
  10. int32_t main()
  11. {
  12.    ios_base::sync_with_stdio(false);
  13.    cin.tie(0);
  14.  
  15.    int t;
  16.    cin >> t;
  17.    while(t--)
  18.    {
  19.         int n;
  20.         string s;
  21.         cin >> n >> s;
  22.  
  23.         vector<long long> pre(n);
  24.         for(int i=0;i<n;i++)
  25.         {
  26.             pre[i]=s[i]-'0';
  27.             if(i)
  28.                 pre[i]=pre[i]+pre[i-1];
  29.         }        
  30.  
  31.         string ans="";
  32.         long long remainder=0;
  33.         for(int i=n-1;i>=0;i--)
  34.         {
  35.             long long curr=remainder+pre[i];
  36.             ans+=(char)(curr%10+'0');
  37.             remainder=curr/10;
  38.         }
  39.  
  40.         while(remainder)
  41.         {
  42.             ans+=(char)(remainder%10+'0');
  43.             remainder=remainder/10;
  44.         }
  45.  
  46.         while(ans.back()=='0')
  47.             ans.pop_back();
  48.         reverse(ans.begin(),ans.end());
  49.  
  50.         cout << ans << "\n";
  51.    }  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement