• [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     
     
     
  • 相关阅读:
    remove-duplicates-from-sorted-list
    combination-sum-ii(熟悉下Java排序)
    decode-string(挺麻烦的)
    subsets-ii(需要思考,包括了子数组的求法)
    remove-duplicates-from-sorted-array
    delete-node-in-a-linked-list
    find-all-duplicates-in-an-array(典型的数组中的重复数,不错,我做出来了,可是发现别人有更好的做法)
    【转载】大型网站架构的演进
    【转载】第三方支付平台相关-支付、对账
    【Todo】JS跨域访问问题的解决
  • 原文地址:https://www.cnblogs.com/sxiszero/p/3617376.html
Copyright © 2020-2023  润新知