首页 > 代码库 > UVa11520 Fill the Square (字典序枚举)
UVa11520 Fill the Square (字典序枚举)
链接:http://vjudge.net/problem/18268
分析:从上到下从左到右按字典序从小到大枚举。
1 #include <cstdio> 2 3 const int maxn = 10 + 5; 4 5 int n; 6 char grid[maxn][maxn]; 7 8 int main() { 9 int T;10 scanf("%d", &T);11 for (int kase = 1; kase <= T; kase++) {12 scanf("%d", &n);13 for (int i = 0; i < n; i++) scanf("%s", grid[i]);14 for (int i = 0; i < n; i++)15 for (int j = 0; j < n; j++) if (grid[i][j] == ‘.‘)16 for (char ch = ‘A‘; ch <= ‘Z‘; ch++) {17 if (i > 0 && grid[i - 1][j] == ch) continue;18 if (i < n - 1 && grid[i + 1][j] == ch) continue;19 if (j > 0 && grid[i][j - 1] == ch) continue;20 if (j < n - 1 && grid[i][j + 1] == ch) continue;21 grid[i][j] = ch; break;22 }23 printf("Case %d:\n", kase);24 for (int i = 0; i < n; i++) printf("%s\n", grid[i]);25 }26 return 0;27 }
UVa11520 Fill the Square (字典序枚举)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。