fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void prefixHash(string s)
  5. {
  6. int n=s.size();
  7. vector<int>ph(n);
  8. int sum=0;
  9. for(int i=0; i<n; i++)
  10. {
  11. sum*=10;
  12. sum+=(s[i]-'0');
  13. ph[i]=sum;
  14. }
  15. cout<<sum<<endl;
  16. for(auto x:ph)cout<<x<<" ";
  17. cout<<endl;
  18.  
  19. }
  20. int main()
  21. {
  22. string s="101245";
  23. int l=2,r=3;
  24. //calcHash(l,r,s);
  25. prefixHash(s);
  26. }
  27.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
101245
1 10 101 1012 10124 101245