Codeforces Round #237 (Div. 2) A. Valera and X(模拟题)

1、http://codeforces.com/contest/404/problem/A

2、题目大意:

给出一个n*n的矩阵,如果对角线是相同的字母,并且其余的是相同的字母,但是与对角线的不同,那么输出YES,否则输出NO

3、题目:

A. Valera and X
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:

  • on both diagonals of the square paper all letters are the same;
  • all other squares of the paper (they are not on the diagonals) contain the same letter that is different from the letters on the diagonals.

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
4、AC代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char a[303][303];
int main()
{
    int n;
    while(scanf("%d",&n)!=EOF)
    {
        getchar();
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
            {
                scanf("%c",&a[i][j]);
            }
            getchar();
        }
        char c=a[1][1];
        int flag=0;
        int k=n;
        for(int i=1;i<=n;i++)
        {
            if(a[i][i]!=c || a[i][k]!=c)
            {
                flag=1;
                break;
            }
            a[i][i]='&';
            a[i][k]='&';
            k--;
        }
        if(flag==1)
        {
            printf("NO\n");
        }
        else
        {
            char d=a[1][2];
            if(d==c)
            {
                printf("NO\n");
            }
            else
            {
                int flag1=0;
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=n;j++)
                {
                    if(a[i][j]!='&')
                    {
                        if(a[i][j]!=d)
                        {
                            flag1=1;
                            break;
                        }
                    }
                }
                if(flag1==1)
                break;
            }
            if(flag1==1)
            {
                printf("NO\n");
            }
            else
            {
                printf("YES\n");
            }
            }

        }
    }
    return 0;
}
/*
3
qqq
qqq
qqq
*/


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值