[Codeforces Round #237 (Div. 2)] A. Valera and X
14038 단어 codeforces
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Valera is a little boy. Yesterday he got a huge Math hometask at school, so Valera didn't have enough time to properly learn the English alphabet for his English lesson. Unfortunately, the English teacher decided to have a test on alphabet today. At the test Valera got a square piece of squared paper. The length of the side equals n squares (n is an odd number) and each unit square contains some small letter of the English alphabet.
Valera needs to know if the letters written on the square piece of paper form letter "X". Valera's teacher thinks that the letters on the piece of paper form an "X", if:
Help Valera, write the program that completes the described task for him.
Input
The first line contains integer n (3 ≤ n < 300; n is odd). Each of the next n lines contains n small English letters — the description of Valera's paper.
Output
Print string "YES", if the letters on the paper form letter "X". Otherwise, print string "NO". Print the strings without quotes.
Sample test(s)
input
5
xooox
oxoxo
soxoo
oxoxo
xooox
output
NO
input
3
wsw
sws
wsw
output
YES
input
3
xpx
pxp
xpe
output
NO
: 。 。
:
3
aaa
aaa
aaa
answer:NO
:
1 #include<stdio.h>
2 #include<stdbool.h>
3 #include<string.h>
4 #include<limits.h>
5 int i,j,n,m;
6 char a[400][400];
7 bool can[400][400];
8
9 int
10 pre()
11 {
12 memset(can,true,sizeof(can));
13 return 0;
14 }
15
16 int
17 main()
18 {
19 int f;
20 f=0;
21
22 pre();
23 scanf("%d",&n);
24 for(i=1;i<=n;i++)
25 scanf("%s",&a[i]);
26
27 for(i=1;i<=(n >> 1);i++)
28 {
29 if(a[i][i-1]!=a[1][0])
30 {
31 f=1;
32 break;
33 }
34 if(a[n-i+1][i-1]!=a[1][0])
35 {
36 f=1;
37 break;
38 }
39 if(a[i][n-i]!=a[1][0])
40 {
41 f=1;
42 break;
43 }
44 if(a[n-i+1][n-i]!=a[1][0])
45 {
46 f=1;
47 break;
48 }
49 }
50 if(a[(n/2)+1][n/2]!=a[1][0]) f=1;
51
52 if (f==1) printf("NO
");
53 else
54 {
55 f=0;
56 for(i=1;i<=(n/2);i++)
57 {
58 can[i][i-1]=false;
59 can[n-i+1][i-1]=false;
60 can[i][n-i]=false;
61 can[n-i+1][n-i]=false;
62 }
63 can[(n/2)+1][n/2]=false;
64
65 for(i=1;i<=n;i++)
66 for(j=0;j<n;j++)
67 if (can[i][j])
68 {
69 if(a[i][j]!=a[1][1])
70 {
71 f=1;
72 break;
73 }
74 }
75 if((f==0)&&(a[1][0]!=a[1][1])) printf("YES
");
76 else printf("NO
");
77
78 }
79
80 return 0;
81 }
82
83
84
85
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces Round #715 Div. 2C The Sports Festival: 구간 DP전형구간 DP의 초전형. 이하, 0-indexed. 입력을 정렬하여 어디서나 시작하고 최적으로 좌우로 계속 유지하면 좋다는 것을 알 수 있습니다. {2000})$의 주문이 된다. 우선, 입력을 소트하여 n개의 요소를 $...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.