putSequence = (int *)malloc(allocateSpace * sizeof(int)); ///存储矩阵的尺寸输入
90
91
92 int ptrOffset = 0; ///指针偏移
93 int tempSize = 0; ///临时存储输入值
94
95 do {
96 cin >> tempSize;
97 if (tempSize <= 0)
98 continue;
99 *(inputSequence + ptrOffset++) = tempSize;
100 if (ptrOffset >= allocateSpace)
101 {
102 allocateSpace += 5;
103 inputSequence = (int*)realloc(inputSequence, allocateSpace * sizeof(int));
104 }
105 } while (tempSize != 0);
106 inputNum = ptrOffset; ///偏移量即输入个数
107 return inputSequence;
108 }
比如求$S_{ad}$,则在控制台输入a b c d 0,然后回车即可。当然 a b c d 必须替换为数字。
代码中用到的一些知识
C++提供模版类string,其中一个构造方法可将字符转化为字符串。如 string(1, 'A'+1),第一个参数是源字符延拓次数,这个构造函数将‘B’转化为"B"。