题解 | #求int型正整数在内存中存储时1的个数#

坐标移动

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

word = input('','s');
words = strsplit(word,';');
origenal = [0,0];
function [out] = islegal(in)
    if length(in) == 3
        if ~isempty(str2num(in(2:3)))
            out = 1;
            return;
        end
    end
    if length(in) == 2
        if ~isempty(str2num(in(2)))
            out = 1;
            return;
        end
    end
    out = 0;
end
function out = opp(in)
    p = in(1);
    q = str2num(in(2:end)); 
    out = [0,0];
    switch p
    case 'A'
         out = [-q,0];
    case 'S'
         out = [0,-q];
    case 'D'
         out = [q,0];
    case 'W'
         out = [0,q];
    otherwise 
         out = [0,0];
    end
end

for lop = 1:length(words)
    
    if islegal(words{lop})
        origenal = origenal+opp(words{lop});
    end
end

fprintf("%d,%d",origenal(1),origenal(2));




全部评论

相关推荐

不愿透露姓名的神秘牛友
06-25 17:22
点赞 评论 收藏
分享
06-26 18:30
门头沟学院 Java
据说名字越长别人越关...:你问问这里面有多少是正经候选人,而不是乱打招呼的
点赞 评论 收藏
分享
想按时下班的我在等o...:我投测试也是这个情况,不知道咋办了
点赞 评论 收藏
分享
白火同学:大二有这水平很牛了,可以适当对关键信息加粗一点,比如关键技术、性能指标之类的。
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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