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. pSubGateBucket += pLastSubGateBucket;
  19. smallGateBucketList[lastIdx].second += pLastSubGateBucket;
  20. lastIdx--;
  21. pLastSubGateBucket = 0;
  22. }
  23. else{
  24. ++idx;
  25. }
  26. }
  27. }
  28.  
  29. int main() {
  30. cout << "Hello Geek!";
  31. //std::vector<std::pair<int,int>> kk;
  32. //kk.push_back(make_pair(2,2));
  33. std::vector<std::pair<unsigned int,unsigned int>> smallGateBucketList;
  34. smallGateBucketList.push_back(make_pair(7, 3));
  35. smallGateBucketList.push_back(make_pair(6, 4));
  36. smallGateBucketList.push_back(make_pair(3, 7));
  37. smallGateBucketList.push_back(make_pair(3, 7));
  38. smallGateBucketList.push_back(make_pair(2, 8));
  39. smallGateBucketList.push_back(make_pair(2, 8));
  40. smallGateBucketList.push_back(make_pair(2, 8));
  41. smallGateBucketList.push_back(make_pair(2, 8));
  42. smallGateBucketList.push_back(make_pair(2, 8));
  43.  
  44. myfUNC(smallGateBucketList);
  45. for(auto& data : smallGateBucketList){
  46. std::cout<<"\n data : "<<data.first<<" , "<<data.second;
  47. }
  48. return 0;
  49. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Hello Geek!
 Merged : data 1 : 7 , 1 : data 2 : 2 , 8
 Merged : data 1 : 6 , 2 : data 2 : 2 , 8
 Merged : data 1 : 8 , 0 : data 2 : 2 , 8
 Merged : data 1 : 3 , 5 : data 2 : 2 , 8
 Merged : data 1 : 5 , 3 : data 2 : 2 , 8
 Merged : data 1 : 7 , 0 : data 2 : 3 , 7
 data : 9 , 1
 data : 10 , 0
 data : 10 , 0
 data : 0 , 10
 data : 0 , 10
 data : 0 , 10
 data : 0 , 10
 data : 0 , 10
 data : 0 , 10