• Codeforces Round #237 (Div. 2) A


    链接:http://codeforces.com/contest/404/problem/A

    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

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    这题作为CF 的A题确实很好,题意很简单,代码很简单,就是有坑,遍地是坑……
    也可以说自己没有身经百战,总是掉坑里。。。。
     1 #include <stdio.h>
     2 #include <string.h>
     3 #include <iostream>
     4 #include <algorithm>
     5 
     6 using namespace std;
     7 
     8 int main()
     9 {
    10     char str[305][305];
    11     int i,j,n;
    12     while(scanf("%d",&n)!=EOF)
    13     {
    14         getchar();
    15         for(i=1; i<=n; i++)
    16         {
    17             for(j=1; j<=n; j++)
    18             {
    19                 scanf("%c",&str[i][j]);
    20             }
    21             getchar();
    22         }
    23         int tmp=n;
    24         char xx=str[1][1];
    25         char yy=str[1][2];
    26         bool flag=true;
    27         if(xx == yy)
    28         {
    29             printf("NO
    ");
    30             continue;
    31         }
    32         for(i=1; i<=n; i++)
    33         {
    34             if(str[i][i] != xx)
    35             {
    36                 //printf("NO
    ");
    37                 flag=false;
    38                 break;
    39             }
    40             if(str[i][tmp] != xx)
    41             {
    42                 //printf("NO
    ")
    43                 flag=false;
    44                 break;
    45             }
    46             tmp--;
    47         }
    48         for(i=1; i<=n; i++)
    49         {
    50             for(j=1; j<=n; j++)
    51             {
    52                 if(str[i][j] != xx && str[i][j] != yy)
    53                 {
    54                     flag = false;
    55                     goto end;
    56                 }
    57             }
    58         }
    59         tmp=n;
    60         for(i=1; i<=n; i++)
    61         {
    62             for(j=1; j<=n; j++)
    63             {
    64                 if(i == j || j == tmp)
    65                     continue;
    66                 if(str[i][j] == xx)
    67                 {
    68                     flag=false;
    69                     //goto end;
    70                 }
    71             }
    72             tmp--;
    73         }
    74     end:;
    75         if(flag)printf("YES
    ");
    76         else printf("NO
    ");
    77     }
    78     return 0;
    79 }
  • 相关阅读:
    Python爬虫之编写一个可复用的下载模块
    Python爬虫之BeautifulSoup的用法
    解决:Python爬取https站点时SNIMissingWarning和InsecurePlatformWarning
    解决:xampp中Apache, MySql, Filezilla端口占用问题
    Python中的Unicode编码和UTF-8编码
    解决:AttributeError: module 'requests' has no attribute 'get'”
    解决:return _compile(pattern, flags).search(string) TypeError: expected string or buffer
    NOIP 2014 提高组 Day1
    NOIP2013 提高组 Day2
    poj 3020 Antenna Placement
  • 原文地址:https://www.cnblogs.com/ccccnzb/p/3914012.html
Copyright © 2020-2023  润新知