我很纳闷这个题目怎么引起Tony的兴趣的。
先写一个,再看你的高见。
程序代码:
#include<stdio.h>
void lines_count(char map[13][13], int * ch, int * cv, int * cd)
{
int i, j;
*ch = *cv = *cd = 0;
for(i = 1; i < 12; i++)
for(j = 1; j < 12; j++)
{
if(map[i][j] != '*') continue;
if(map[i][j - 1] != '*' && map[i][j + 1] == '*') (*ch)++;
if(map[i - 1][j] != '*' && map[i + 1][j] == '*') (*cv)++;
if(map[i - 1][j - 1] != '*' && map[i + 1][j + 1] == '*') (*cd)++;
if(map[i - 1][j + 1] != '*' && map[i + 1][j - 1] == '*') (*cd)++;
}
}
int main()
{
char map[13][13], str[16];
int i, j, hlines, vlines, dlines;
for(i = 0; i < 13; i++)
for(gets(str), j = 0; j < 13; map[i][j] = str[j++]);
lines_count(map, &hlines, &vlines, &dlines);
printf("The grid contains\n");
printf(" - %d horizontal lines\n", hlines);
printf(" - %d vertical lines\n", vlines);
printf(" - %d diagonal lines\n", dlines);
return 0;
}