fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5. #include<math.h>
  6.  
  7. int digit(int x)
  8. {
  9. int count=0;
  10. if(x==0)
  11. return 1;
  12.  
  13. else
  14. {
  15. while(x!=0)
  16. {
  17. x=x/10;
  18. count++;
  19. }
  20. }
  21.  
  22. return count;
  23. }
  24.  
  25. int main() {
  26. // your code goes here
  27. int n;
  28. cin>>n;
  29. vector<int>arr(n);
  30. int i=0;
  31. while(i<n)
  32. {
  33. cin>>arr[i];
  34. i++;
  35. }
  36.  
  37. int sum=0;
  38. int prefix[n+1]={0};
  39. prefix[0]=arr[0];
  40. for(int i=1;i<n;i++)
  41. {
  42. prefix[i]=prefix[i-1]+arr[i];
  43. }
  44. for(int j=1;j<n;j++)
  45. { int i=0;
  46. int p = pow(10,digit(arr[j]));
  47. sum+=prefix[j-1]*p+arr[j]*(j-i) ;
  48.  
  49.  
  50. }
  51. cout<<sum;
  52.  
  53. return 0;
  54. }
Success #stdin #stdout 0.01s 5292KB
stdin
3
3 14 15
stdout
2044