[C++] Map and count
Count the number of each kind of food on each table.\n\n# Explanation\n\nBecause there are two items to index, table and food, so counting is a little troubleso
Count the number of each kind of food on each table.\n\n# Explanation\n\nBecause there are two items to index, table and food, so counting is a little troublesome. But because the number of tables and food are small (<= 500 and <= 20), I created a map for each table counting the number of food.\n\n# C++ Solution\n\n```cpp\nclass Solution {\npublic:\n    vector<vector<string>> displayTable(vector<vector<string>>& orders) {\n        set<string> foodSet;\n        map<int, map<string, int>> tableMap;\n        for (const auto& order: orders) {\n            foodSet.insert(order[2]);\n            tableMap[stoi(order[1])][order[2]]++;\n        }\n        \n        vector<vector<string>> ans;\n        vector<string> head = {"Table"};\n        for (auto food: foodSet)\n            head.push_back(food);\n        ans.push_back(head);\n        int m = head.size();\n        \n        for (auto& p: tableMap) {\n            int tableNum = p.first;\n            vector<string> table(m, "0");\n            table[0] = to_string(tableNum);\n            int i = 1;\n            for (auto& food: foodSet) {\n                if (p.second.find(food) != p.second.end())\n                    table[i] = to_string(p.second[food]);\n                i += 1;\n            }\n            ans.push_back(table);\n        }\n        \n        return ans;\n    }\n};\n```\n
[]