fork(3) download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <sstream>
  5.  
  6. using namespace std;
  7.  
  8. inline void getFirstLine(string & r, string &h, string & e, char & d);
  9. inline void getHeaders(vector <string> & headers, char delimiter, vector <unsigned short> & colMaxLen, string & h);
  10. inline void processLine(string & line, vector < vector<string> > & data, vector <unsigned short> & colMaxLen, char delimiter, string & e);
  11. inline void printHeaders(vector <string> & headers, vector <unsigned short> & colMaxLen, string & r, vector < vector<string> > & data);
  12. inline void printData(vector < vector<string> > & data, vector <unsigned short> & colMaxLen, string & r);
  13.  
  14. int main()
  15. {
  16. cin.sync_with_stdio(false);
  17. vector <vector <string>> data;
  18. vector <string> headers;
  19. vector <unsigned short> colMaxLen;
  20. string r, h, e, line;
  21. char d;
  22. getFirstLine(r, h, e, d);
  23. getHeaders(headers, d, colMaxLen, h);
  24. while (getline(cin, line)) {
  25. processLine(line, data, colMaxLen, d, e);
  26. }
  27. if (h[0] == 'T') // jesli nalezy wyswietlic naglowki
  28. printHeaders(headers, colMaxLen, r, data);
  29. printData(data, colMaxLen, r);
  30. }
  31.  
  32. inline void getFirstLine(string & r, string & h, string & e, char & d)
  33. {
  34. string line, word;
  35. cin >> r >> h >> e >> d;
  36. getline(cin, line);
  37. }
  38.  
  39. inline void getHeaders(vector<string>& headers, char delimiter, vector <unsigned short> & colMaxLen, string & h)
  40. {
  41. headers.clear();
  42. string line, word;
  43. getline(cin, line);
  44. stringstream ss(line);
  45. while (getline(ss, word, delimiter)) {
  46. headers.push_back(word);
  47. // jesli nie nalezy wyswietlac naglowkow, to nie trzeba wydluzac kolumny
  48. int d = (h[0] == 'F') ? 0 : word.length();
  49. colMaxLen.push_back(d);
  50. }
  51. }
  52.  
  53. inline void processLine(string & line, vector<vector<string>>& data, vector <unsigned short> & colMaxLen, char delimiter, string & e)
  54. {
  55. vector <string> v;
  56. stringstream ss(line);
  57. string word;
  58. while (getline(ss, word, delimiter)) {
  59. // edycja pustych pol
  60. word = (word == "") ? e : word;
  61. int len = word.length();
  62. int i = v.size(); // rozmiar v jest jednoczesnie id slowa z nastepnej kolumny
  63. if (len > colMaxLen[i])
  64. colMaxLen[i] = len;
  65. v.push_back(word);
  66. }
  67. data.push_back(v);
  68. }
  69.  
  70. inline void printHeaders(vector<string>& headers, vector<unsigned short>& colMaxLen, string & r, vector < vector<string> > & data)
  71. {
  72. int dd = data.size();
  73. if (r[0] == 'T') { // jesli nalezy wyswietlic id, to nalezy powiekszyc odstep w naglowku
  74. string space(to_string(data.size()).length() + 2, ' ');
  75. cout << space;
  76. }
  77. for (int i = 0; i < headers.size(); i++)
  78. {
  79. int s = (i > 0) ? 2 : 0;
  80. string word = headers[i];
  81. string space(colMaxLen[i] + s - word.length(), ' ');
  82. cout << space << word;
  83. }
  84. cout << '\n';
  85. }
  86.  
  87. inline void printData(vector<vector<string>>& data, vector<unsigned short>& colMaxLen, string & r)
  88. {
  89. bool printNums = (r[0] == 'T') ? true : false;
  90. int len = to_string(data.size()).length();
  91.  
  92. for (int line = 0; line < data.size(); line++)
  93. {
  94. if (printNums) {
  95. string space(len - to_string(line+1).length(), ' ');
  96. cout << space << line+1 << " ";
  97. }
  98.  
  99. vector <string> * record = &data[line];
  100. for (int i = 0; i < record->size(); i++)
  101. {
  102. int s = (i > 0) ? 2 : 0;
  103. string word = record->at(i);
  104. string space(colMaxLen[i] + s - word.length(), ' ');
  105. cout << space << word;
  106. }
  107. cout << '\n';
  108. }
  109. }
  110.  
Success #stdin #stdout 0s 3468KB
stdin
True True N/A ,
ID,DATE,USER,RESULT,TIME,MEM,LANG
13394870,2015-01-10 21:43:39,aakash,accepted,0.16,1341M,JAVA
13392496,2015-01-10 15:37:50,Utkarsh,wrong answer,0.00,7.5M,PYTH 2.7
13391470,2015-01-10 13:21:17,Utkarsh,wrong answer,0.00,7.5M,PYTH 2.7
13391442,2015-01-10 13:13:40,Utkarsh,wrong answer,0.00,7.5M,PYTH 2.7
13390989,2015-01-10 12:01:18,aakash,wrong answer,0.16,1341M,JAVA
13390787,2015-01-10 11:38:27,aakash,wrong answer,0.16,1341M,JAVA
13390774,2015-01-10 11:37:04,aakash,wrong answer,0.10,1341M,JAVA
13390718,2015-01-10 11:29:55,aakash,runtime error (NZEC),0.10,1341M,JAVA
13390707,2015-01-10 11:29:02,aakash,compilation error,,,JAVA
13390699,2015-01-10 11:28:00,aakash,runtime error (NZEC),0.11,1341M,JAVA
13390691,2015-01-10 11:27:06,aakash,compilation error,,,JAVA
13390438,2015-01-10 10:59:55,aakash,runtime error (NZEC),0.14,1341M,JAVA
13390423,2015-01-10 10:58:15,aakash,compilation error,,,C++ 4.3.2
13389991,2015-01-10 09:52:26,aakash,runtime error (NZEC),0.15,1341M,JAVA
13272813,2014-12-26 15:28:37,Bijoy Rahman Arif,wrong answer,0.00,2.2M,C
13272302,2014-12-26 15:01:17,Bijoy Rahman Arif,wrong answer,0.00,2.2M,C
13271177,2014-12-26 14:11:06,Bijoy Rahman Arif,wrong answer,0.00,2.2M,C
13271154,2014-12-26 14:07:42,Bijoy Rahman Arif,wrong answer,0.00,2.2M,C
13270804,2014-12-26 13:21:45,Bijoy Rahman Arif,wrong answer,0.00,2.2M,C
13270641,2014-12-26 13:01:45,Bijoy Rahman Arif,wrong answer,0.01,2.2M,C
stdout
          ID                 DATE               USER                RESULT  TIME    MEM       LANG
 1  13394870  2015-01-10 21:43:39             aakash              accepted  0.16  1341M       JAVA
 2  13392496  2015-01-10 15:37:50            Utkarsh          wrong answer  0.00   7.5M   PYTH 2.7
 3  13391470  2015-01-10 13:21:17            Utkarsh          wrong answer  0.00   7.5M   PYTH 2.7
 4  13391442  2015-01-10 13:13:40            Utkarsh          wrong answer  0.00   7.5M   PYTH 2.7
 5  13390989  2015-01-10 12:01:18             aakash          wrong answer  0.16  1341M       JAVA
 6  13390787  2015-01-10 11:38:27             aakash          wrong answer  0.16  1341M       JAVA
 7  13390774  2015-01-10 11:37:04             aakash          wrong answer  0.10  1341M       JAVA
 8  13390718  2015-01-10 11:29:55             aakash  runtime error (NZEC)  0.10  1341M       JAVA
 9  13390707  2015-01-10 11:29:02             aakash     compilation error   N/A    N/A       JAVA
10  13390699  2015-01-10 11:28:00             aakash  runtime error (NZEC)  0.11  1341M       JAVA
11  13390691  2015-01-10 11:27:06             aakash     compilation error   N/A    N/A       JAVA
12  13390438  2015-01-10 10:59:55             aakash  runtime error (NZEC)  0.14  1341M       JAVA
13  13390423  2015-01-10 10:58:15             aakash     compilation error   N/A    N/A  C++ 4.3.2
14  13389991  2015-01-10 09:52:26             aakash  runtime error (NZEC)  0.15  1341M       JAVA
15  13272813  2014-12-26 15:28:37  Bijoy Rahman Arif          wrong answer  0.00   2.2M          C
16  13272302  2014-12-26 15:01:17  Bijoy Rahman Arif          wrong answer  0.00   2.2M          C
17  13271177  2014-12-26 14:11:06  Bijoy Rahman Arif          wrong answer  0.00   2.2M          C
18  13271154  2014-12-26 14:07:42  Bijoy Rahman Arif          wrong answer  0.00   2.2M          C
19  13270804  2014-12-26 13:21:45  Bijoy Rahman Arif          wrong answer  0.00   2.2M          C
20  13270641  2014-12-26 13:01:45  Bijoy Rahman Arif          wrong answer  0.01   2.2M          C