fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. #include <vector>
  5. #include <fstream>
  6. #include <cstdlib>
  7.  
  8. #define NUM_FIELDS 3
  9. struct SplitLine {
  10. std::string fields[NUM_FIELDS];
  11. };
  12.  
  13. /* DONT MAKE ANY CHANGES ABOVE THIS LINE */
  14.  
  15. /* If you wish you can include any more files here.
  16.   (from standard libraries only) */
  17.  
  18. std::map<std::string, int> process_data(std::vector<struct SplitLine> data) {
  19. /*
  20.   * Modify this function to process `data` as indicated
  21.   * in the question. At the end, return the appropriate
  22.   * value.
  23.   *
  24.   * Please create appropriate classes, and use appropriate
  25.   * data structures as necessary.
  26.   *
  27.   * Do not print anything in this function.
  28.   *
  29.   * Note: the existing program is not intended to be an example
  30.   * of good programming practice. (For example, struct
  31.   * SplitLine is not a very good way to hold the data for this
  32.   * problem.) However, the code that *you* write will be
  33.   * evaluated on the basis of the quality of the code, use of
  34.   * appropriate classes/data-structures, comments, and
  35.   * efficiency of the algorithm used.
  36.   *
  37.   * Submit this entire program (not just this function)
  38.   * as your answer
  39.   */
  40. std::map<std::string, int> ret_val;
  41. return ret_val;
  42. }
  43.  
  44. /* DONT MAKE ANY CHANGES BELOW THIS LINE */
  45.  
  46. int main(void) {
  47. std::ifstream in("input.txt");
  48. std::vector<struct SplitLine> input_data;
  49. while (in) {
  50. struct SplitLine line;
  51. for (int i=0; i<NUM_FIELDS; i++) {
  52. if (i==NUM_FIELDS-1)
  53. std::getline(in, line.fields[i]);
  54. else
  55. std::getline(in, line.fields[i], ',');
  56. }
  57. if (line.fields[0] != "")
  58. input_data.push_back(line);
  59. }
  60. std::ofstream out("output.txt");
  61. std::map<std::string, int> ret_val = process_data(input_data);
  62. for (std::map<std::string, int>::iterator it = ret_val.begin();
  63. it != ret_val.end();
  64. it++) {
  65. out << it->first << ": " << it->second << std::endl;
  66. }
  67. return 0;
  68. }
  69.  
  70.  
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
Standard output is empty