Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么调试运行没有错误!!!它就是WA呢???郁闷啊!!!!哪位大牛看看!!!!

Posted by win1611 at 2010-01-20 16:29:05 on Problem 2612
#include<stdio.h>
#include<string.h>

int M;      //总共有M列M列
void DisCode(char code[][15]);
int search(char code[][15],int i,int j);

int main()
{
	int i=0,j,NO;
	int flag=0;
	scanf("%d",&M);
	char code[15][15],key[15][15];     //扫雷地图中雷的位置用*表示出来 人探索的结果用Key保存
	while(i<M)
	{
		memset(code[i],'\0',sizeof(char)*M);
		scanf("%s",code[i]);           //输入扫雷游戏中雷以及非雷的位置分布
		i++;
	}
	for(i=0;i<M;i++)
		scanf("%s",&key[i]);
	for(i=0;i<M;i++)
	{
		j=0;
		while(key[i][j]!='.')
		{
			if(code[i][j]=='*')
			{
				DisCode(code);
				flag=1;
				break;
			}
			NO=search(code,i,j);
			if(key[i][j]=='x')
				key[i][j]=NO+'0';
			j++;
		}
		if(flag==1)
			break;
	}
	for(i=0;i<M;i++)
	{
		for(j=0;j<M;j++)
			printf("%c",key[i][j]);
		printf("\n");
	}

	return 0;
}
void DisCode(char code[][15])
{
	int i,j;
	for(i=0;i<M;i++)
	{
		for(j=0;j<M;j++)
			printf("%c",code[i][j]);
		printf("\n");
	}
}
int search(char code[][15],int i,int j)
{
	int num=0,k,t;     //用num用来返回此时周围雷的个数
	for(k=i-1;k<=i+1;k++)
		for(t=j-1;t<=j+1;t++)
			if(code[k][t]&&code[k][t]=='*') //如果它存在并且它与*相等 则num++
				num++;
	return num;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator