题解 | #坐标移动#

坐标移动

https://www.nowcoder.com/practice/119bcca3befb405fbe58abe9c532eb29

#include <stdio.h>
void judge(char std[], int(*p)[2], int i, int hash[])
{
    int num = 0;
    if (i >= 2 && i <= 3)
    {
        if ((std[1]>='0'&& std[1] <= '9'))
        {
            if (i == 3&& (std[2] >= '0' && std[2] <= '9'))
            {
                num = (std[1] - '0') * 10 + (std[2] - '0');
            }
            else if(i==2)
            {
                num = std[1] - '0';
            }
            if (std[0] == 'A' || std[0] == 'D')
            {
                (*p)[0] += hash[std[0]] * num;
            }
            else if (std[0] == 'W' || std[0] == 'S')
            {
                (*p)[1] += hash[std[0]] * num;
            }
        }
    }
}
int main()
{
    int arr1[2] = { 0 };
    int* p = arr1;
    char std[1000] = { 0 };
    char word = getchar();
    int hash[127] = { 0 };
    hash['A'] = -1;
    hash['D'] = 1;
    hash['W'] = 1;
    hash['S'] = -1;
    while (word != '\n')
    {
        int i = 0;
        while (word != ';')
        {
            std[i++] = word;
            word = getchar();
        }
        judge(std, &arr1, i, hash);
        word = getchar();
    }
    printf("%d,%d\n", arr1[0], arr1[1]);
    return 0;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务