p10677求条
  • 板块灌水区
  • 楼主MC_is_my_dad
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/10/13 10:54
  • 上次更新2024/10/13 12:20:23
查看原帖
p10677求条
1498872
MC_is_my_dad楼主2024/10/13 10:54

卡在 #7 了

#include <bits/stdc++.h>
using namespace std;
char a[1010][1010];
int dx[] = {0, 0, 1, -1};
int dy[] = {-1, 1, 0, 0};
int main()
{
	int n, m;
	char maxxx = ' ';
	cin >> n >> m;
	for (int i = 1; i <= n; i ++)
		for (int j = 1; j <= m; j ++)
		{
			cin >> a[i][j];
			maxxx = max (maxxx, a[i][j]);
		}

	string ans = "";
	for (int i = 1; i <= n; i ++)
		for (int j = 1; j <= m; j ++)
		{
			if (a[i][j] == maxxx)
			{
				char maxx = '#';
				for (int k = 0; k < 4; k ++)
				{
					int x = i + dx[k], y = j + dy[k];
					if (x < 1 || x > n || y < 1 || y > m) continue;
	                if (a[x][y] > maxx) maxx = a[x][y];
				}
			//	cout << a[i][j] << " " << maxx << '\n';
	            if (maxx != '#' && maxx != a[i][j])
				{
					string s;
					s = a[i][j];
					s += maxx;
				//	cout << s << "\n";
					if (ans != "") ans = max (ans, s);
					else ans = s;
				}
				else
				{
					string s;
					s = a[i][j];
					if (ans != "") ans = max (ans, s);
					else ans = s;
				}
			}
		}
    cout << ans;
	return 0;
}
2024/10/13 10:54
加载中...