fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct STUDENT_SCORE
  5. {
  6. char name[16];
  7. char id[16];
  8. int eng;
  9. const bool operator<( const STUDENT_SCORE& rhs ) const
  10. {
  11. return eng < rhs.eng;
  12. }
  13. };
  14.  
  15. #include <vector>
  16. #include <algorithm>
  17.  
  18. int main()
  19. {
  20. vector< STUDENT_SCORE > scores;
  21. char inputs[ 256 ];
  22. while( cin.getline( inputs, sizeof inputs ) )
  23. {
  24. STUDENT_SCORE score;
  25. sscanf( inputs, "%s%s%u", score.name, score.id, &score.eng );
  26. scores.emplace_back( score );
  27. }
  28. sort( scores.begin(), scores.end() );
  29. int last_score = -1;
  30. int last_order;
  31. for( int i = 0; i < scores.size(); ++i )
  32. {
  33. const auto& score = scores[ i ];
  34. int order = i + 1;
  35. if( last_score != score.eng )
  36. {
  37. last_score = score.eng;
  38. last_order = order;
  39. }
  40. else
  41. {
  42. order = last_order;
  43. }
  44. cout << score.name << " " << score.id << " " << score.eng << " " << order << endl;
  45. }
  46.  
  47. return 0;
  48. }
  49.  
Success #stdin #stdout 0s 3464KB
stdin
다다 3333 20
나나 2222 10
가가 1111 10
stdout
나나 2222 10 1
가가 1111 10 1
다다 3333 20 3