C语言蓝桥杯刷题:递增序列

题目链接
C语言蓝桥杯刷题:递增序列_第1张图片

#include 
#include 

int main(int argc, char *argv[])
{
    
    int count = 0;//标记递增序列个数
    int i = 0;//标记行号
    int j = 0;//标记列号
    int x = 0;//xy为遍历到元素的行号列号
    int y = 0;
    //读取数据
    char arr[30][50]={"VLPWJVVNNZSWFGHSFRBCOIJTPYNEURPIGKQGPSXUGNELGRVZAG",
                    "SDLLOVGRTWEYZKKXNKIRWGZWXWRHKXFASATDWZAPZRNHTNNGQF",
                    "ZGUGXVQDQAEAHOQEADMWWXFBXECKAVIGPTKTTQFWSWPKRPSMGA",
                    "BDGMGYHAOPPRRHKYZCMFZEDELCALTBSWNTAODXYVHQNDASUFRL",
                    "YVYWQZUTEPFSFXLTZBMBQETXGXFUEBHGMJKBPNIHMYOELYZIKH",
                    "ZYZHSLTCGNANNXTUJGBYKUOJMGOGRDPKEUGVHNZJZHDUNRERBU",
                    "XFPTZKTPVQPJEMBHNTUBSMIYEGXNWQSBZMHMDRZZMJPZQTCWLR",
                    "ZNXOKBITTPSHEXWHZXFLWEMPZTBVNKNYSHCIQRIKQHFRAYWOPG",
                    "MHJKFYYBQSDPOVJICWWGGCOZSBGLSOXOFDAADZYEOBKDDTMQPA",
                    "VIDPIGELBYMEVQLASLQRUKMXSEWGHRSFVXOMHSJWWXHIBCGVIF",
                    "GWRFRFLHAMYWYZOIQODBIHHRIIMWJWJGYPFAHZZWJKRGOISUJC",
                    "EKQKKPNEYCBWOQHTYFHHQZRLFNDOVXTWASSQWXKBIVTKTUIASK",
                    "PEKNJFIVBKOZUEPPHIWLUBFUDWPIDRJKAZVJKPBRHCRMGNMFWW",
                    "CGZAXHXPDELTACGUWBXWNNZNDQYYCIQRJCULIEBQBLLMJEUSZP",
                    "RWHHQMBIJWTQPUFNAESPZHAQARNIDUCRYQAZMNVRVZUJOZUDGS",
                    "PFGAYBDEECHUXFUZIKAXYDFWJNSAOPJYWUIEJSCORRBVQHCHMR",
                    "JNVIPVEMQSHCCAXMWEFSYIGFPIXNIDXOTXTNBCHSHUZGKXFECL",
                    "YZBAIIOTWLREPZISBGJLQDALKZUKEQMKLDIPXJEPENEIPWFDLP",
                    "HBQKWJFLSEXVILKYPNSWUZLDCRTAYUUPEITQJEITZRQMMAQNLN",
                    "DQDJGOWMBFKAIGWEAJOISPFPLULIWVVALLIIHBGEZLGRHRCKGF",
                    "LXYPCVPNUKSWCCGXEYTEBAWRLWDWNHHNNNWQNIIBUCGUJYMRYW",
                    "CZDKISKUSBPFHVGSAVJBDMNPSDKFRXVVPLVAQUGVUJEXSZFGFQ",
                    "IYIJGISUANRAXTGQLAVFMQTICKQAHLEBGHAVOVVPEXIMLFWIYI",
                    "ZIIFSOPCMAWCBPKWZBUQPQLGSNIBFADUUJJHPAIUVVNWNWKDZB",
                    "HGTEEIISFGIUEUOWXVTPJDVACYQYFQUCXOXOSSMXLZDQESHXKP",
                    "FEBZHJAGIFGXSMRDKGONGELOALLSYDVILRWAPXXBPOOSWZNEAS",
                    "VJGMAOFLGYIFLJTEKDNIWHJAABCASFMAKIENSYIZZSLRSUIPCJ",
                    "BMQGMPDRCPGWKTPLOTAINXZAAJWCPUJHPOUYWNWHZAKCDMZDSR",
                    "RRARTVHZYYCEDXJQNQAINQVDJCZCZLCQWQQIKUYMYMOVMNCBVY",
                    "ABTCRRUXVGYLZILFLOFYVWFFBZNFWDZOADRDCLIRFKBFBHMAXX"};



    for (i = 0;i < 30;i++)
    {
        for (j = 0;j < 50;j++)
        {
            //横向
            for (y = j;y < 50;y++)
            {
                if (arr[i][j] < arr[i][y])//横向比较:行不变,列变
                {
                    count++;
                }
            }

            //纵向
            for (x = i;x < 30;x++)
            {
                if (arr[i][j] < arr[x][j])//纵向比较:行变,列不变
                {
                    count++;
                }
            }

            //右下
            for (x = i, y = j;x < 30 && y < 50;x++, y++)//斜向右下走,x和y都是在变大的
            {
                if (arr[i][j] < arr[x][y])
                {
                    count++;
                }
            }

            //右上
            for (x = i, y = j;x >= 0&&y < 50;x--, y++)//斜向右上走,x在减小,y在增大
            {
                if (arr[i][j] < arr[x][y])
                {
                    count++;
                }
            }

            //左下
            for (x = i, y = j;x < 30&&y >= 0;x++, y--)//斜向左下走,x在增大,y在减小
            {
                if (arr[i][j] <arr[x][y])
                {
                    count++;
                }
            }
        }
    }
    printf("%d", count);
  return 0;
}

C语言蓝桥杯刷题:递增序列_第2张图片
示例:
LANN
QIAO

横向:LN LN AN AN IO AO
纵向:LQ AI NO
右斜向下:NO
右斜向上: IN AN
左斜向下:AQ
左斜向上:
题中说只有13个递增序列,所以就没有左斜向上了,
这也是我觉得这个题目的大病,当时蓝桥杯估计也坑死一群人

关于斜向,因为右上和左下其实是一条线,如果想改进代码,可以把两个for循环合成一个,然后判断的时候,只要不相同就是+1,因为左下如果是小于,对于右下其实是大于,反之亦然。

你可能感兴趣的:(蓝桥杯,蓝桥杯,c语言,算法)