求助,WA on #10
查看原帖
求助,WA on #10
801051
Wolves_487楼主2024/7/1 13:52
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+10;
char c[N][N];
int n,m;
int pos1,pos2;
char a,b;
int dx[5]={0,1,-1,0,0};
int dy[5]={0,0,0,1,-1};
signed main(){
	cin>>n>>m;
	
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++) 
		{
			cin>>c[i][j];
			if(c[i][j]!='#')
			{
				if(c[i][j]>a) 
				{
					a=c[i][j];
			    }
			}
		}
		  
	}
	for(int i=1;i<=n;i++)
	{
	    for(int j=1;j<=m;j++)
	    {
	         if(c[i][j]==a)
	         {
	             for(int k=1;k<=4;k++)
	            {
		            int xx=i+dx[k];
		            int yy=j+dy[k];
		            if(xx>=1&&xx<=n&&yy>=1&&yy<=n&&c[xx][yy]!='#')
		            {
			            b=max(b,c[xx][yy]);
		            }
	            }
	         }
	    }
	}
		
	if(a==b) cout<<a<<endl;
	else cout<<a<<b<<endl; 
	return 0;
}//调了半天也没看出哪错了qwq

2024/7/1 13:52
加载中...