byd为什么这题输入不能用scanf
查看原帖
byd为什么这题输入不能用scanf
643244
DI_520楼主2024/10/30 14:40

本来输入用scanf和getchar都是0分(见注释),换成cin就AC了(害得我浪费了1小时)。有没有大佬能解释一下原理?

#include<iostream>
#include<cstring>
using namespace std;
int t,n,m,k,ans,x,y,d;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
char c;
bool a[10001][10001],re[10001][10001];
int main()
{
	scanf("%ld",&t);
	while(t--)
	{
//		scanf("%ld%ld%ld%ld%ld%ld",&n,&m,&k,&x,&y,&d);
		cin>>n>>m>>k>>x>>y>>d;
		memset(re,0,sizeof(re));
		ans=1;
		re[x][y]=1;
		for(int i=1;i<=n;i++)
		{
//			getchar();
			for(int j=1;j<=m;j++)
			{
//				c=getchar();
//				scanf("%c",&c);
				cin>>c;
				if(c=='.') a[i][j]=0;
				else a[i][j]=1;
			}
		}
		while(k--)
		{
			int x_=x+dx[d],y_=y+dy[d];
			if(x_>=1 && x_<=n && y_>=1 && y_<=m && !a[x_][y_])
			{
				x=x_;
				y=y_;
				if(!re[x][y]) ans++;
				re[x][y]=1;
//				printf("(%ld,%ld)\n",x,y);
			}
			else d=(d+1)%4;
		}
		printf("%ld\n",ans);
	}
	return 0;
}
2024/10/30 14:40
加载中...