fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int getCount(int x){
  4. int count=0;
  5. while(x!=0){
  6. x=x/10;
  7. count++;
  8.  
  9. }
  10. return count;
  11. }
  12.  
  13. int main() {
  14. // your code goes here
  15. int arr[]={10,2};
  16. int n=sizeof(arr)/sizeof(arr[0]);
  17. int sumArray=0;
  18. for(int i=0;i<n;i++){
  19. sumArray=sumArray+arr[i];
  20. }
  21. int digit[10]={0}; //digit array to get count of digit in number
  22. for(int i=0;i<n;i++){
  23. int y=getCount(arr[i]);
  24. digit[y]=digit[y]+1;
  25. }
  26. int val=0;
  27. int sum=0;
  28. for(int i=1;i<n;i++){
  29. int j=1;
  30. while(j<=6){ //Becuase the contraints has a number containing the digit size of 6
  31. val+=arr[i]*pow(10,j)*digit[j];
  32. j++; //while looop used to get all digit size of 1 ,2 .. for the given element at i as we want all possible number for ith element
  33. }
  34. sum+=val+sumArray;
  35. }
  36. cout<<"The sum is:"<<sum;
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5328KB
stdin
Standard input is empty
stdout
The sum is:232