Code:

#include <iostream> #include <cstdio> #include <string> using namespace std; bool is_it_max(int* arr, int a,int size){ int i = 0,buf = a; while(i < size){ if(a < arr[i] ){ a = arr[i]; } i++; } if(buf == a){ return true; } else return false; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int n = 0; int v = 1, sum = 0; cin>>n; int i =0; int* arr = new int[n]; while(i < n){ cin >> arr[i]; i++; } cout << sum; for(int j = 0; j < n;j++){ if(is_it_max(arr,arr[j],n)){ sum+=(arr[j]*v); v-=v; arr[j] = 0; } else arr[j] = 0; v++; } cout << sum << endl; delete[] arr; } 

Input data:

five

73 31 96 24 46

The desired result is 380, but I get 0380, how to get rid of this zero in front of the number, tried to take the remainder of dividing this number by 1000, displays the same

I solve the problem for this link.

    1 answer 1

    Well, remove the first conclusion

      cout << sum; 

    at that moment when sum is 0, what's the problem? ...

    • Thanks, I sat for half an hour I could not understand what the problem was) - nick