Advertisement
niamul64

SET function demo||sort and print || ICPC Dhaka Regional Pre

Sep 27th, 2019
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.10 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. set < pair<int, pair<int,string> > >setST;
  5.  
  6. void fistLine()
  7. {
  8.     printf("-------------------------");
  9. }
  10.  
  11. void OneDas()
  12. {
  13.     printf(" | ");
  14. }
  15.  
  16. void firstLine()
  17. {
  18.  
  19.     printf("Roll");
  20.     OneDas();
  21.     printf("Name      ");
  22.     OneDas();
  23.     printf("Marks\n");
  24.     printf("-------------------------\n");
  25.  
  26. }
  27.  
  28.  
  29. void printST()
  30. {
  31.     int i;
  32.     set < pair<int, pair<int,string> > >:: iterator it,it2;
  33.  
  34.     for(it=setST.begin(); it!=setST.end(); it++)
  35.     {
  36.  
  37.         it2=it;
  38.         it2++;
  39.         if(it2!=setST.end() && ((*it2).first < ((*it).first)) )
  40.         {
  41.  
  42.             printf("%4d",(*it2).second.first);
  43.             OneDas();
  44.             cout<<(*it2).second.second;
  45.  
  46.             for(i=((*it2).second.second).size(); i<10; i++)
  47.             {
  48.                 cout<<" ";
  49.             }
  50.             OneDas();
  51.             printf("%d",((-1)*((*it2).first)));
  52.             printf("\n");
  53.             printf("%4d",(*it).second.first);
  54.             OneDas();
  55.             cout<<(*it).second.second;
  56.  
  57.             for(i=((*it).second.second).size(); i<10; i++)
  58.             {
  59.                 cout<<" ";
  60.             }
  61.             OneDas();
  62.             printf("%d",((-1)*((*it).first)));
  63.             printf("\n");
  64.             setST.erase(it);
  65.             setST.erase(it2);
  66.             continue;
  67.  
  68.  
  69.  
  70.         }
  71.         printf("%4d",(*it).second.first);
  72.         OneDas();
  73.         cout<<(*it).second.second;
  74.  
  75.         for(i=((*it).second.second).size(); i<10; i++)
  76.         {
  77.             cout<<" ";
  78.         }
  79.         OneDas();
  80.         printf("%d",((-1)*((*it).first)));
  81.         printf("\n");
  82.  
  83.  
  84.     }
  85.  
  86.  
  87. }
  88.  
  89.  
  90. int main ()
  91. {
  92.     int i,rol,marks,j,k,cas;
  93.     string nam;
  94.     cin>>cas;
  95.     for(i=0; i<cas; i++)
  96.     {
  97.         cin>>rol>>nam>>marks;
  98.         marks=marks*(-1);
  99.         setST.insert(make_pair(marks,make_pair(rol,nam)));
  100.     }
  101.     firstLine();
  102.  
  103.     printST();
  104.  
  105.  
  106.  
  107.     return 0;
  108. }
  109.  
  110.  
  111.  
  112. //Roll | Name       | Marks
  113. //-------------------------
  114. //   1 | kabul      | 100
  115. //   7 | babul      | 0
  116. //  20 | abul       | 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement