这么多人赞的吗~其实巧妙的方法不是没有。
class array {
public:
int operator[](size_t index) {
return index;
}
};
还可以做得更骚,但手机码字就懒得撸了(并不是因为买不起电脑啊!是因为睡前才刷的知乎)
//////以下是原答案//////
告诉你标准答案。手机码字…将就着看吧…
int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99};
如果打表的成本低,那就打表。