欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1926B.Vlad and Shapes
Vlad and Shapes
Vladislav has a binary square grid of cells. A triangle or a square is drawn on the grid with symbols 1. As he is too busy being cool, he asks you to tell him which shape is drawn on the grid.
- A triangle is a shape consisting of () consecutive rows, where the -th row has consecutive characters
1, and the central1s are located in one column. An upside down triangle is also considered a valid triangle (but not rotated by 90 degrees).
Two left pictures contain examples of triangles: , . The two right pictures don't contain triangles.
- A square is a shape consisting of () consecutive rows, where the -th row has consecutive characters
1, which are positioned at an equal distance from the left edge of the grid.
Examples of two squares: , .
For the given grid, determine the type of shape that is drawn on it.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer () — the size of the grid.
The next lines each contain characters 0 or 1.
The grid contains exactly one triangle or exactly one square that contains all the 1s in the grid. It is guaranteed that the size of the triangle or square is greater than (i.e., the shape cannot consist of exactly one 1).
Output
For each test case, output "SQUARE" if all the 1s in the grid form a square, and "TRIANGLE" otherwise (without quotes).
Samples
6
3
000
011
011
4
0000
0000
0100
1110
2
11
11
5
00111
00010
00000
00000
00000
10
0000000000
0000000000
0000000000
0000000000
0000000000
1111111110
0111111100
0011111000
0001110000
0000100000
3
111
111
111
SQUARE
TRIANGLE
SQUARE
TRIANGLE
TRIANGLE
SQUARE
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |