• 谜题 UVA227


    这道题目还是不难的,但是要注意gcc里面gets已经不能用了,用gets_s还是可以的,尽管我并不知道有什么区别

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    int main()
    {
    char a[20][20]; int x, y; char s[1000];
    int blank_x = 0, blank_y = 0; int flag = 1;
    gets_s(a[0]);
    gets_s(a[1]);
    gets_s(a[2]);
    gets_s(a[3]);
    gets_s(a[4]);
    /*for (x = 0; x < 5; x++)
    {
    for (y = 0; y < 5; y++)
    {
    scanf("%c", &a[x][y]);
    }
    }*/
    for (int x = 0; x < 5; x++)
    {
    for (int y = 0; y < 5; y++)
    {
    if (a[x][y] = ' ')
    {
    blank_x = x;
    blank_y = y;
    }
    }
    }
    gets_s(s);
    int len = strlen(s);
    for (int i = 0; i < len; i++)
    {
    if (s[len - 1] == '0' || s[i] == 'A' || s[i] == 'R' || s[i] == 'B' || s[i] == 'L')
    {
    if (s[i] == 'A'&&blank_x != 0)
    {
    a[blank_x][blank_y] = a[blank_x - 1][blank_y];
    a[blank_x - 1][blank_y] = ' ';
    }
    if (s[i] == 'R'&&blank_y != 4)
    {
    a[blank_x][blank_y] = a[blank_x][blank_y + 1];
    a[blank_x][blank_y + 1] = ' ';
    }
    if (s[i] == 'B'&&blank_x != 4)
    {
    a[blank_x][blank_y] = a[blank_x + 1][blank_y];
    a[blank_x + 1][blank_y] = ' ';
    }
    if (s[i] == 'L'&&blank_y != 0)
    {
    a[blank_x][blank_y] = a[blank_x][blank_y - 1];
    a[blank_x][blank_y - 1] = ' ';
    }
    }
    else flag = 0;
    }
    if (flag)
    {
    for (int i = 0; i < 5; i++)
    {
    printf("%c %c %c %c %c ", a[i][0], a[i][1], a[i][2], a[i][3], a[i][4]);
    }
    }
    else printf("the puzzle has no final configuration! ");
    system("pause");
    }

  • 相关阅读:
    左右对齐Justify遇到的坑
    JS中的相等性判断===, ==, Object.is()
    JS调用栈的一些总结
    VueI18n
    【转】Webpack 快速上手(下)
    【转】Webpack 快速上手(中)
    【转】Webpack 快速上手(上)
    springboot打包排除指定jar包依赖
    prometheus+grafana搭建
    fbctf 安装部署出现的问题
  • 原文地址:https://www.cnblogs.com/guohaoyu110/p/5887232.html
Copyright © 2020-2023  润新知