<\/span><\/h2>\n\n\n\nThe first line contains t<\/em><\/strong>, the number of test cases.
Each of the t<\/em><\/strong> subsequent lines contains two space-separated integers. The first integer is a color value, c<\/em><\/strong>, and the second integer is a fruit value, f<\/em><\/strong>.<\/p>\n\n\n\n<\/span>Constraints<\/strong><\/span><\/h2>\n\n\n\n- 1 <= t<\/em> <= 100<\/strong><\/li>
- – 2 x 109<\/sup> <= c<\/em> <= 2 x 109<\/sup><\/strong><\/li>
- – 2 x 109<\/sup> <= f<\/em> <= 2 x 109<\/sup><\/strong><\/li><\/ul>\n\n\n\n
<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nThe locked stub code in your editor prints t<\/em><\/strong> lines containing the color<\/em> name and the fruit<\/em> name corresponding to the input enumeration index.<\/p>\n\n\n\nSample Input<\/strong><\/p>\n\n\n\n2\n1 0\n3 3<\/code><\/pre>\n\n\n\nSample Output<\/strong><\/p>\n\n\n\ngreen apple\nunknown unknown<\/code><\/pre>\n\n\n\nExplanation<\/strong><\/p>\n\n\n\nSince t = 2<\/strong><\/em>, there are two lines of output.<\/p>\n\n\n\n- The two input index values, 1<\/strong> and 0<\/strong>, correspond to green<\/em> in the color enumeration and apple<\/em> in the fruit enumeration. Thus, we print
green apple<\/code>.<\/li>- The two input values, 3<\/strong> and 3<\/strong>, are outside of the range of our enums. Thus, we print
unknown unknown<\/code>.<\/li><\/ol>\n\n\n\n<\/span>Solution – C++ Class Template Specialization in C++<\/strong><\/span><\/h2>\n\n\n\n<\/span>C++<\/strong><\/span><\/h3>\n\n\n\n#include <iostream>\nusing namespace std;\nenum class Fruit { apple, orange, pear };\nenum class Color { red, green, orange };\n\ntemplate <typename T> struct Traits;\n\n\/\/ Define specializations for the Traits class template here.\ntemplate <> \nstruct Traits<Fruit>{\n static string name(int index){\n switch(index){\n case 0:return \"apple\";\n case 1: return \"orange\" ;\n case 2: return \"pear\";\n } \n return \"unknown\";\n } \n};\ntemplate <> \nstruct Traits<Color>{\n static string name(int index){\n switch(index){\n case 0:return \"red\";\n case 1: return \"green\" ;\n case 2: return \"orange\"; \n }\n return \"unknown\"; \n } \n};\n\n\n\nint main()\n{\n\tint t = 0; std::cin >> t;\n\n for (int i=0; i!=t; ++i) {\n int index1; std::cin >> index1;\n int index2; std::cin >> index2;\n cout << Traits<Color>::name(index1) << \" \";\n cout << Traits<Fruit>::name(index2) << \"\\n\";\n }\n}\n<\/pre>\n\n\n\n