首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PEP-8 -检查Word是否为回文

PEP-8 -检查Word是否为回文
EN

Stack Overflow用户
提问于 2015-11-19 02:59:56
回答 1查看 613关注 0票数 0

我已经为回文程序整理了输入,但是我一点也不知道如何检查输入的单词是不是回文。

代码语言:javascript
复制
; Program to read name and output greeting 
            BR  main 
        name:   .BLOCK 32           ;space for up to 32 characters 
    msg1:   .ASCII "The word is: \x00" 
    msg2:   .ASCII "Enter a word: \x00" 
    main:   LDX 0,i             ; load index register with 0
            STRO    msg2,d      ;output word prompt 
    chin:   CHARI   name,x          ;read a character 
            LDA name,x      ;and load accumulator 
            ADDX    1,I     ;add 1 to index register 
            CPA 0x0A00,i    ;compares with line feed 
            BREQ    out     ;if line feed go to out 
            BR  chin        ;go to chin to read next char 
    out:    LDA '\x00',I        ;load acc with end of string 
            STA name,x      ;store end of string in name block
            STRO    msg1,d      ;output word message 
            STRO    name,d      ;output stored name
            STOP 
    .END

有人能帮我解决这个问题吗?谢谢。

EN

回答 1

Stack Overflow用户

发布于 2015-11-19 03:07:12

下面是一些简单的C-ish伪代码,可以帮助您入门:

代码语言:javascript
复制
Left = Start;
Right = Start + Length - 1;

while (Left <= Right)  
{
  if Word[Left] != Word[Right]
    not a palindrome, exit
  Left++;
  Right--;
}
palindrome
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33788184

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档