fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <utility>
  4. using namespace std;
  5.  
  6. void myfUNC(std::vector<std::pair<unsigned int,unsigned int>>& smallGateBucketList)
  7. {
  8. unsigned int idx = 0;
  9. unsigned int lastIdx = smallGateBucketList.size() - 1;
  10. while(idx < lastIdx){
  11. unsigned int& pSubGateBucket = smallGateBucketList[idx].first;
  12. unsigned int& remSubBucketSize = smallGateBucketList[idx].second;
  13. unsigned int& pLastSubGateBucket = smallGateBucketList[lastIdx].first;
  14. if(remSubBucketSize >= pLastSubGateBucket) {
  15. smallGateBucketList[idx].second -= pLastSubGateBucket;
  16. std::cout<<"\n Merged : data 1 : "<<pSubGateBucket<<" , "<<remSubBucketSize;
  17. std::cout<<" : data 2 : "<<pLastSubGateBucket<<" , "<<smallGateBucketList[lastIdx].second;
  18. lastIdx--;
  19. pLastSubGateBucket = 0;
  20. }
  21. else{
  22. ++idx;
  23. }
  24. }
  25. }
  26.  
  27. int main() {
  28. cout << "Hello Geek!";
  29. //std::vector<std::pair<int,int>> kk;
  30. //kk.push_back(make_pair(2,2));
  31. std::vector<std::pair<unsigned int,unsigned int>> smallGateBucketList;
  32. smallGateBucketList.push_back(make_pair(8000, 2000));
  33. smallGateBucketList.push_back(make_pair(6000, 4000));
  34. smallGateBucketList.push_back(make_pair(5000, 5000));
  35. smallGateBucketList.push_back(make_pair(4000, 6000));
  36. smallGateBucketList.push_back(make_pair(2000, 8000));
  37. smallGateBucketList.push_back(make_pair(500, 9500));
  38. smallGateBucketList.push_back(make_pair(200, 9800));
  39. smallGateBucketList.push_back(make_pair(50, 9950));
  40.  
  41. myfUNC(smallGateBucketList);
  42. for(auto& data : smallGateBucketList){
  43. std::cout<<"\n data : "<<data.first<<" , "<<data.second;
  44. }
  45. return 0;
  46. }
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
Hello Geek!
 Merged : data 1 : 8000 , 1950 : data 2 : 50 , 9950
 Merged : data 1 : 8000 , 1750 : data 2 : 200 , 9800
 Merged : data 1 : 8000 , 1250 : data 2 : 500 , 9500
 Merged : data 1 : 6000 , 2000 : data 2 : 2000 , 8000
 Merged : data 1 : 5000 , 1000 : data 2 : 4000 , 6000
 data : 8000 , 1250
 data : 6000 , 2000
 data : 5000 , 1000
 data : 0 , 6000
 data : 0 , 8000
 data : 0 , 9500
 data : 0 , 9800
 data : 0 , 9950