fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <string>
  4. #include <vector>
  5. #include <map>
  6. #include <functional>
  7. #include <stdio.h>
  8. #include <math.h>
  9. using namespace std;
  10.  
  11. typedef std::vector<int> vi;
  12. typedef std::vector<pair<int, int> > vii;
  13. struct P{
  14. string name;
  15. int a, d;
  16. bool operator < (const P &p) const{
  17. return name < p.name;
  18. }
  19. }p[10];
  20. int main() {
  21. int t, i, ca;
  22.  
  23. cin >> t;
  24. for(ca=1;ca<=t;ca++){
  25. for(i=0;i<10;i++)
  26. cin>>p[i].name>>p[i].a>>p[i].d;
  27. for(i=0;i<9;i++)
  28. for(int j=0;j<9-i;j++)
  29. if(p[j+1].a>p[j].a || (p[j+1].a==p[j].a&& (p[j+1].d<p[j].d || (p[j+1].d==p[j].d&&p[j+1].name<p[j].name) )))
  30. swap(p[j], p[j+1]);
  31. sort(p, p+5);
  32. sort(p+5, p+10);
  33. printf("Case %d:\n(",ca);
  34. cout<<p[0].name;
  35. for(i=1;i<5;i++) cout<<", "<< p[i].name;
  36. cout<<")\n("<<p[5].name;
  37. for(i=6;i<10;i++) cout<<", "<< p[i].name;
  38. cout<<")"<<endl;
  39.  
  40. }
  41. return 0;
  42. }
Success #stdin #stdout 0s 3484KB
stdin
2
sameezahur 20 21
sohelh 18 9
jaan 17 86
sidky 16 36
shamim 16 18
shadowcoder 12 9
muntasir 13 4
brokenarrow 16 16
emotionalblind 16 12
tanaeem 20 97
sameezahur 20 21
sohelh 18 9
jaan 17 86
sidky 16 36
shamim 16 18
shadowcoder 12 9
muntasir 13 4
brokenarrow 16 16
emotionalblind 16 12
tanaeem 20 97
stdout
Case 1:
(emotionalblind, jaan, sameezahur, sohelh, tanaeem)
(brokenarrow, muntasir, shadowcoder, shamim, sidky)
Case 2:
(emotionalblind, jaan, sameezahur, sohelh, tanaeem)
(brokenarrow, muntasir, shadowcoder, shamim, sidky)