14

假设我有一个字符串,它采用我想读入的形式,"## ##"例如. 这很简单:stdin"15 16"

I HAS A STRINGY
GIMMEH STRINGY

这会从字符串中抓取整行stdin并将其存储到字符串中——呃,对不起,YARN——称为STRINGY.

我将如何提取字符串中的两个整数?我希望能够将 15 和 16 分别存储为整数(LULZ I MEANS NUMBR)。

4

1 回答 1

16

简短的回答:

你不能在 LOLCODE 1.2 中做到这一点。

长答案:

由于在提议的 1.3 规范中没有YARN操作函数,也无法将 aYARN转换为类似 a 的东西BUKKIT(因此我们可以将字符串模拟为一个BUKKIT字符),因此不可能从这样的字符串中提取数字。

仅使用 1.2 规范,我们仍然可以完成这项工作,我猜...

由于字符串连接已经存在于 1.2 asSMOOSH ... MKAY中,理论上你可以str01通过, 来保留变量str99,然后...

IM IN YR readloop UPPIN YR throwawayvariable WILE BOTH OF NOT broken AN DIFFRINT currentyarn AN STRINGY
    str01, WTF?
        OMG "Z"
            str99 R str98
            str98 R str97
            str97 R str96
            ...
            str02 R str01
            str01 R ""
            GTFO
        OMG "Y"
            str01 R "Z";
            GTFO
        OMG "X"
            str01 R "Y";
            GTFO
        ...
        OMG "0"
            str01 R "1";
            GTFO
        OMG ""
            str01 R "0"
            GTFO
        OMGWTF
            I HAS A ERRORMSG
            ERRORMSG R SMOOSH "I DUNNO WAT U SAY, illegal character", str01 MKAY
            VISIBLE ERRORMSG
            broken R WIN
            GTFO
    OIC
    currentyarn R SMOOSH str01, str02, str03, str04, ..., str98, str99 MKAY
IM OUTTA YR readloop

接下来,获取 NUMBR...

NOT broken, O RLY? YA RLY
    yarnnumber R ""
    done R FAIL
    IM IN YR parseloop UPPIN YR otherthrowaway WILE NOT done
        EITHER OF BOTH SAEM str01 AN " " AN BOTH SAEM str01 AN "", O RLY? YA RLY
            number1 R 0
            DIFFRINT yarnnumber AN "", O RLY? YA RLY
                number1 R MAEK yarnnumber A NUMBR
            OIC
            done R WIN
        MEBBE DIFFRINT str01 AN ""
            yarnnumber R SMOOSH yarnnumber, str01 MKAY
        OIC
        str01 R str02
        str02 R str03
        str03 R str04
        ...
        str98 R str99
        str99 R ""
    IM OUTTA YR parseloop

    yarnnumber R ""
    done R FAIL
    IM IN YR parseloop2 UPPIN YR otherthrowaway2 WILE NOT done
        EITHER OF BOTH SAEM str01 AN " " AN BOTH SAEM str01 AN "", O RLY? YA RLY
            number2 R 0
            DIFFRINT yarnnumber AN "", O RLY? YA RLY
                number2 R MAEK yarnnumber A NUMBR
            OIC
            done R WIN
        MEBBE DIFFRINT str01 AN ""
            yarnnumber R SMOOSH yarnnumber, str01 MKAY
        OIC
        str01 R str02
        str02 R str03
        str03 R str04
        ...
        str98 R str99
        str99 R ""
    IM OUTTA YR parseloop2
OIC

最后,你想对他们做什么。

I HAZ A result
result R SUM OF number1 AN number2
VISIBLE result

对于...,填写剩余的使用str##变量的语句。

如果您要使用它,我建议您使用某些东西为您生成 LOLCODE,手动编写它是不可行的。特别是如果您必须支持更长的输入行,例如 255 或 1024 个字符。

于 2015-08-27T12:42:55.550 回答