我需要一种方法来将一个大数组的最新3个值存储到一个单独的数组中,但是在我的生活中,我无法找到如何对它进行编码。
它是朝这个方向发展的:
int w[3] = {0, 0, 0};
int x[12] = {0, 2, 4, 6, 4, 2, 0, 2, 4, 6, 4, 2};
w[0] = x[i];
w[1] = x[i-1];
w[2] = x[i-2];所以如果i=2,那么:
w[0] = x[2] = 4
w[1] = x[2-1] = 2
w[2] = x[2-2] = 0关键是要在这样的代码中使用它:
for (i=0; i<200; i++){
//store x[i], x[i-1] and x[i-2] into 'w' for every value 'i'
//compensate for undefined 'x'-values (such as x[0-1] and x[0-2] )
//by writing '0' to corresponding 'w'
}发布于 2014-03-13 01:52:17
根据以下情况更新:
w[2] = w[1];
w[1] = w[0];
w[0] = x[i];发布于 2014-03-13 01:49:46
w[0] = 0;
w[1] = 0;
w[2] = 0;
w[0] = x[i];
if (i>=1)
{
w[1] = x[i-1] ;
}
if ( i>= 2)
{
w[2] = x[i-2];
}https://stackoverflow.com/questions/22367499
复制相似问题