题解 | #求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-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
迟缓的斜杠青年巴比Q...:简历被投过的公司卖出去了,我前两天遇到过更离谱的,打电话来问我有没有意向报班学Java学习,服了,还拿我学校一个学长在他们那报班学了之后干了华为OD当招牌
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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