【问题标题】:PEP-8 - Checking to See if Word is a PalindromePEP-8 - 检查 Word 是否为回文
【发布时间】:2015-11-18 18:59:56
【问题描述】:

我已经为回文程序整理了输入,但我对如何检查输入的单词是否是回文一无所知。

; 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

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

【问题讨论】:

    标签: assembly palindrome pep8-assembly


    【解决方案1】:

    这里有一些简单的 C-ish 伪代码可以帮助您入门:

    Left = Start;
    Right = Start + Length - 1;
    
    while (Left <= Right)  
    {
      if Word[Left] != Word[Right]
        not a palindrome, exit
      Left++;
      Right--;
    }
    palindrome
    

    【讨论】:

    • 你能给我一些助记符让我乱用吗?我需要的那些?如果我有这些,我很确定我可以做到。
    • @HelloWorld - 你的问题中已经有很多,使用它们(和你自己的头脑)
    猜你喜欢
    • 1970-01-01
    • 2013-08-11
    • 2017-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多