题解 | #坐标移动#

坐标移动

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

line = input('', 's');
lines = strsplit(line, ';');
n = length(lines);
axis = [0, 0];
for i = 1:n
    move = lines(i);
    move = cell2mat(move);
    if length(move) == 3 || length(move) == 2
        if isstrprop(move(2), 'digit')&&isstrprop(move(end), 'digit')
            l = str2num(move(2:end));
            switch move(1)
                case('A')
                    axis(1) = axis(1)-l;
                case('S')
                    axis(2) = axis(2)-l;
                case('W')
                    axis(2) = axis(2)+l;
                case('D')
                    axis(1) = axis(1)+l;
                otherwise
                    continue
            end
        else 
            continue
        end
    else 
        continue
    end
end
fprintf('%d,%d', axis(1), axis(2))

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 12:11
我最近都有点不想活了,天天早10晚11的,还问我爱不爱她目前的状态别说爱谁了,没扇谁就不错了。是不是大家都是一进节子,只有工作没有爱情了
AzureSkies:在字节的时候找的就是字节的,飞书太适合恋爱人士了,能看到是不是已读,是不是在会议中。简直冥婚好伴侣
投递字节跳动等公司9个岗位
点赞 评论 收藏
分享
强大的马里奥:不太可能,我校计算机硕士就业率99%
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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