考验细心程度;提交了几遍都没过~~
AC代码:
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
const int N = 101;
int t, n, m, g[N][N];
void pt(int i, int j, int k) //逐一编号输出
{
if ( k == 0 ) printf(“%d %d %d %d %d %d\n”, i, j, i, j + 1, i + 1, j);
else if ( k == 1 ) printf(“%d %d %d %d %d %d\n”, i, j, i - 1, j, i, j + 1);
else if ( k == 2 ) printf(“%d %d %d %d %d %d\n”, i, j, i - 1, j, i, j - 1);
else if ( k == 3 ) printf(“%d %d %d %d %d %d\n”, i, j, i, j - 1, i + 1, j);
}
int main()
{
scanf(“%d”,&t);
while( t– )
{
scanf(“%d%d”,&n,&m);
int sum = 0;
for( int i=1; i<=n; i )
{
for( int j=1; j<=m; j )
{
scanf(“%1d”,&g[i][j]);
if( g[i][j] == 1 ){
sum += 3;
}
}
}
printf(“%d\n”,sum);
for( int i=1; i<=n; i )
{
for( int j=1; j<=m; j )
{
if( g[i][j] == 1 )
{
if( i < n && j < m ) {
pt(i, j, 0); pt(i, j+1, 3); pt(i+1, j, 1);
}
else if( i == n && j == m ){
pt(i, j, 2); pt(i-1, j, 3); pt(i, j-1, 1);
}
else if( i == n ){
pt(i, j, 1); pt(i-1, j, 0); pt(i, j+1, 2);
}
else{
pt(i, j, 3); pt(i, j-1, 0); pt(i+1, j, 2);
}
}
}
}
}
return 0;
}