fork(1) download
  1. #include <vector>
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. const unsigned int RESULTING_SEQUENCE_SIZE = 10;
  7.  
  8. int main() {
  9. double currentMember;
  10. vector <double> inputSequence;
  11. double resultingSequence[RESULTING_SEQUENCE_SIZE]{0};
  12. // Adds a new element to the vector to the end of the input stream
  13. while (cin >> currentMember) {
  14. inputSequence.push_back(currentMember);
  15. }
  16. sort(inputSequence.begin(), inputSequence.end()); // Sort ascending initial sequence
  17. for (int i = 0; i < RESULTING_SEQUENCE_SIZE; i++) {
  18. // Accumulate the sum of suitable elements to the corresponding member of the result sequence
  19. for (auto currentMember : inputSequence) {
  20. resultingSequence[i] += (i < currentMember && currentMember <= i + 1 ? currentMember : 0);
  21. }
  22. }
  23. // Output the sequence
  24. for (auto currentMember : resultingSequence) {
  25. cout << currentMember << " ";
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0s 3468KB
stdin
2.02 42 1.998 3 7.43 3.33 3.03 5.56 5 5.5
stdout
0 1.998 5.02 6.36 5 11.06 0 7.43 0 0