这是我的一些代码。我试图保持2d数组的总运行量。
我有一个随机数生成器来生成二维数组中的x和y位置。该位置在x和y位置添加2,在正下方,上方,右侧和左侧添加1。这可能会发生多次。我需要将所有输入数组的值加起来。

我无法获得总的工作量。即时通讯不确定如何添加输入到2d数组中的值。有谁知道如何做到这一点?

int paintSplatterLoop(int ary [ROWS][COLS])
{
double bagCount,
       simCount,
       totalCupCount = 0.0;//accumulator, init with 0

double totalRowCount = 0, totalColCount=0;

double simAvgCount = 0;
double cupAvgCount;

for (simCount = 1; simCount <= 1; simCount++)
{
    for (bagCount = 1; bagCount <= 2; bagCount++)
    {
        for (int count = 1; count <= bagCount; count++);
        {
            int rRow = (rand()%8)+1;
            int rCol = (rand()%6)+1;
            ary[rRow][rCol]+=2;
            ary[rRow-1][rCol]+=1;
            ary[rRow+1][rCol]+=1;
            ary[rRow][rCol-1]+=1;
            ary[rRow][rCol+1]+=1;
        }
        totalRowCount += ary [rRow][rCol];
        totalColCount += rCol;
    }

}
totalCupCount = totalRowCount + totalColCount;
cout<<"total cups of paint "<<totalCupCount<<"\n"<<endl;

 return totalCupCount;
}

最佳答案

这就是我对二维数组的内容求和的方式:

关于c++ - 如何保持2D阵列的总运行量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19280014/

10-11 18:40