F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Isosceles Right Triangles

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 285    Accepted Submission(s): 150


Problem Description
Apple is a very careless girl. One day, the teacher leaves her a problem which has stuck her for a long while. Apple turns to you with this problem: counting the number of the isosceles right triangles composed with various letters in a capital letters matrix. And there are only two forms of the isosceles right triangle in the matrix:
Form 1:
Two right sides are both parallel with the sides of the matrix. e.g.


Form 2:
The hypotenuse is parallel with one side of the matrix. e.g.


Notice that all the isosceles right triangles should contain more than or equal to three letters.
 

Input
The first line of the input file contains a single integer t ( 1 ¡Ü t ¡Ü 20 ), the number of test cases, followed by the input data for each test case. The first line of each test case consists of one integer K ( 1 ¡Ü K ¡Ü 50). K is the size of matrix. The follow K lines, each lines has K capital letters, describe a K*K character matrix. There is no space both at the beginning and the end of all the lines.
 

Output
For each collection, output "Case k:", where k is the number of the test case. To every letter appeared in the matrix, it is required to count the number of the isosceles and right triangles in the matrix composed with it. Moreover, the output should be arrayed in the nature order of these letters in a dictionary. A blank should be left between the letter and its corresponding number. We confirm that the result are less than 2^31.
 

Sample Input
2 3 AAB ABB BBC 4 AABB ABBB BBBB BBBB
 

Sample Output
Case 1: A 1 B 3 C 0 Case 2: A 1 B 50
 

Author
Seraf
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 17:34:47, Gzip enabled