fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6.  
  7. int main() {
  8. // your code goes here
  9.  
  10. vector<int> v;
  11. size_t prevCapacity = v.capacity();
  12.  
  13. size_t capacityChangeCount = 0;
  14. int val = 0;
  15.  
  16. for(; capacityChangeCount<25; ++val)
  17. {
  18. v.push_back(val);
  19. size_t curCapacity = v.capacity();
  20. if (prevCapacity!=curCapacity)
  21. {
  22. cout<<"Capacity changed from "<<prevCapacity<<" to "<<curCapacity;
  23. size_t percent = 0;
  24. if (prevCapacity)
  25. {
  26. percent = 100*curCapacity/prevCapacity;
  27. cout<<" - "<<percent<<"%";
  28. }
  29. cout<<"\n";
  30.  
  31. prevCapacity = curCapacity;
  32. ++capacityChangeCount;
  33. }
  34. }
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0.05s 68968KB
stdin
Standard input is empty
stdout
Capacity changed from 0 to 1
Capacity changed from 1 to 2 - 200%
Capacity changed from 2 to 4 - 200%
Capacity changed from 4 to 8 - 200%
Capacity changed from 8 to 16 - 200%
Capacity changed from 16 to 32 - 200%
Capacity changed from 32 to 64 - 200%
Capacity changed from 64 to 128 - 200%
Capacity changed from 128 to 256 - 200%
Capacity changed from 256 to 512 - 200%
Capacity changed from 512 to 1024 - 200%
Capacity changed from 1024 to 2048 - 200%
Capacity changed from 2048 to 4096 - 200%
Capacity changed from 4096 to 8192 - 200%
Capacity changed from 8192 to 16384 - 200%
Capacity changed from 16384 to 32768 - 200%
Capacity changed from 32768 to 65536 - 200%
Capacity changed from 65536 to 131072 - 200%
Capacity changed from 131072 to 262144 - 200%
Capacity changed from 262144 to 524288 - 200%
Capacity changed from 524288 to 1048576 - 200%
Capacity changed from 1048576 to 2097152 - 200%
Capacity changed from 2097152 to 4194304 - 200%
Capacity changed from 4194304 to 8388608 - 200%
Capacity changed from 8388608 to 16777216 - 200%