這題如果這樣寫可以嗎?
[C++] 純文本查看 復制代碼 #include<iostream>
#include<time.h>
using namespace std;
int main()
{
cin.tie( NULL );
int t=0;//宣告變數
cin>>t;//讀入測資數量
for(int times=0;times<t;times++)
{
int m=0,n=0,k=0;
int ans=0;
cin>>m>>n>>k;//m代表y軸,n代表x軸,k代表z軸
int rice[m][n];
for(int e=0;e<m;e++)//讀入測資
{
for(int f=0;f<n;f++)
{
cin>>rice[e][f];
}
}
for(int e=0;e<m;e++)//判斷上下左右或自己是1,計數器加一
{
for(int f=0;f<n;f++)
{
if(rice[e][f]==1 || rice[e-1][f]==1 || rice[e+1][f]==1 || rice[e][f+1]==1)
{
ans++;
//cout<<ans<<'\n';
}
else if(f != 0 && rice[e][f]==0)
{
if(rice[e][f-1]==1)
{
ans++;
//cout<<ans<<'\n';
}
}
//cout<<"rice["<<e<<"]["<<f<<"]"<<'\n';
}
}
cout<<(m*n*k)-(ans*3)<<'\n';
}
//cout<<clock();
return 0;
} |