12
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

はちみーのうたオートマトン書いてみた

Last updated at Posted at 2021-05-03

こんにちは!バイオインフォマティクス系オタク会社員のroadricefieldです!今日はGW暇なので以下の𝐴𝑣𝑒𝑛𝑡𝑎𝑑𝑜𝑟さんのTweetのトーカイテイオーの「はちみーのうた」オートマトンをPythonで書いてみました.

import sys

class AutoUmaton:
    kashi = ["はちみー", "をなめるとー", "あしがー", "はやくーなる"]
    state = 0
    def transition(self, ip):
        print(self.kashi[self.state])
        if self.state == 0:
            if(ip):
                self.state = 1
            else:
                pass
        elif self.state == 1:
            if(ip):
                self.state = 0
            else:
                self.state = 2
        elif self.state == 2:
            if(ip):
                self.state = 3
            else:
                pass
        elif self.state == 3:
            if(not ip):
                self.state = 0
            else:
                pass

def main():
    try:
        S = list(map(int,list(input())))
    except:
        print("トレーナー!入力がちがうよ!!", file=sys.stderr)
    Teiou = AutoUmaton()
    for i in S: Teiou.transition(i)

main()

入力例

000100011

出力例

はちみー
はちみー
はちみー
はちみー
をなめるとー
あしがー
あしがー
あしがー
はやくーなる  

クラスを作るいい練習になったと思います.

おしまい

12
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?