zoukankan      html  css  js  c++  java
  • [Codeforces Round #237 (Div. 2)] A. Valera and X

    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 < 300n 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     
     
     
  • 相关阅读:
    把数组排成最小的数
    整数中1出现的次数
    连续子数组的最大和
    快速排序
    penCV入门
    OpenCV视频操作
    linux下导入oracle数据表
    js工作备注
    oracle创建默认表空间---重要
    oracle的导入导出
  • 原文地址:https://www.cnblogs.com/sxiszero/p/3617376.html
Copyright © 2011-2022 走看看