fork(1) download
  1. /*
  2.   Zenit CK 2011/2012, uloha d)
  3.   Riesenie by Zemco
  4.  
  5.   Formatovac a vykreslovac tabuliek futbalovych strelcov.
  6.   Predpoklady: padol aspon jeden gol, nikto nedal viac ako 999 golov.
  7.   */
  8. #include<iostream>
  9. #include<map>
  10. #include<string>
  11. #include<vector>
  12. #include<algorithm>
  13. #include<sstream>
  14. using namespace std;
  15.  
  16. typedef vector<string> VS;
  17. typedef map<int,VS> int2VS;
  18.  
  19. //mapa: strelec -> pocet golov
  20. map<string,int> M;
  21. //mapa: pocet golov -> zoznam strelcov
  22. int2VS S;
  23. //sirky stlpcov
  24. int stlpce[3];
  25.  
  26. //vypis vodorovnu oddelujucu ciaru
  27. void outline(){
  28. cout << "+" << string(stlpce[0]+2,'-') << "+" << string(stlpce[1]+2,'-') << "+" << string(stlpce[2]+2,'-') << "+" << endl;
  29. }
  30.  
  31. //vrati pocet znakov, ktore zabera cislo
  32. int dlzkazapisu(int cislo){
  33. ostringstream os;
  34. os << cislo;
  35. return os.str().length();
  36. }
  37.  
  38. int main(){
  39.  
  40. //nacitame strelcov, zistime rozne hodnoty strelenych golov a pre kazdu, kto vsetko ich nastrielal
  41. string s;
  42. while(cin >> s) M[s]++;
  43. for(map<string,int>::iterator it = M.begin(); it != M.end(); it++){
  44. S[(*it).second].push_back( (*it).first );
  45. }
  46. //vyhodime tych, co nejsu dost dobri aby sa dostali do tabulky :)
  47. int miest = min(10,(int)S.size());
  48. while(S.size() > 10) S.erase(S.begin());
  49.  
  50. //zistime si sirky stlpcov
  51. stlpce[0] = miest == 10 ? 3 : 2;
  52. stlpce[1] = 0;
  53. for(int2VS::iterator it = S.begin(); it != S.end(); it++){
  54. for(int i=0;i<(int)(*it).second.size(); i++) stlpce[1] = max(stlpce[1],(int)(*it).second[i].length());
  55. }
  56. stlpce[2] = 1;
  57. int2VS::iterator itt = S.end(); itt--;
  58. stlpce[2] = dlzkazapisu( (*itt).first );
  59.  
  60. //pre kazdu hodnotu vypiseme tych, ktori ju dosiahli
  61. outline();
  62. int umiestnenie = 1;
  63. for( int2VS::reverse_iterator it = S.rbegin(); it != S.rend(); it++){
  64. for(int j=0;j<(int)(*it).second.size();j++){
  65. if ( j == 0 ){
  66. cout << "| " << umiestnenie << ". ";
  67. if (miest == 10 && umiestnenie!=10) cout << " ";
  68. }
  69. else cout << "|" << string(stlpce[0]+2,' ');
  70. cout << "| " << (*it).second[j] << string(stlpce[1]+1-(*it).second[j].length(),' ') << "| ";
  71. if ( j == 0 ) cout << (*it).first << string(stlpce[2] - dlzkazapisu((*it).first),' ');
  72. else cout << string(stlpce[2],' ');
  73. cout << " |" << endl;
  74. }
  75. outline();
  76. umiestnenie++;
  77. }
  78.  
  79. return 0;
  80. }
Runtime error #stdin #stdout 0.01s 2736KB
stdin
Standard input is empty
stdout
Standard output is empty