cody challenge Problem 45. Make a Palindrome Number 判断对称数值

写了48行才实现,感觉自己好蠢[],又找不到别的实现方法

function out = find_palindrome(y)
    a(1)=fix(y/100);
    z=y-100*a(1);
    a(2)=fix(z/10);
    a(3)=mod(z,10);
    frag=false;
    e=zeros(1,10);
 for i=1:100
    lf=length(a);
    e=zeros(1,10);
    b=[];
        for i=1:lf            
        b(lf-i+2)=a(lf-i+1)+a(i)+e(lf-i+2);
        if b(lf-i+2)>=10
            e(lf-i+1)=fix(b(lf-i+2)/10) ;
            b(lf-i+1)=fix(b(lf-i+2)/10);
            b(lf-i+2)=mod(b(lf-i+2),10);
        end
        end 
    if b(1)~=0
     a=b;
    else
        a=b;
        a(1)=[];
    end
    for i=1:fix(length(a)/2)
        if a(i)~=a(length(a)-i+1)
        frag=true; 
        break;
        else
           frag=false;  
        end
    end
        if frag==false
            break;
        end
end
cen=1;
for i=1:length(a)
    d(i)=a(i)*cen;
    cen=cen*10;
end
cen1=0;
for i=1:length(d)
    cen1=cen1+d(i);
end
out=cen1;
end

请教

posted @ 2020-10-14 21:08  Aneverforget  阅读(93)  评论(0编辑  收藏  举报