少し前に、文字列の乗算に関する課題がありました。数値だけでなく文字列も乗算できる方法を示しました。ただし、数字に文字列を適切に掛けることはできません。そうする試みが1つありましたが、これは明らかに間違っています。修正する必要があります!
あなたのタスク:
文字列と整数の2つの入力を乗算する関数またはプログラムを作成します。文字列に整数を(適切に)乗算するには、文字列を文字に分割し、各文字を整数に等しい回数繰り返してから、文字を元に戻します。整数が負の場合、最初のステップでその絶対値を使用し、文字列を逆にします。入力が0の場合、何も出力しません(0を掛けたものは何も等しくありません)。
入力:
印刷可能なASCII文字と改行のみで構成される文字列、および整数(負の可能性あり)。
出力:
文字列に整数を掛けたもの。
例:
Hello World!, 3 --> HHHeeellllllooo WWWooorrrlllddd!!!
foo, 12 --> ffffffffffffoooooooooooooooooooooooo
String, -3 --> gggnnniiirrrtttSSS
This is a fun challenge, 0 -->
Hello
World!, 2 --> HHeelllloo
WWoorrlldd!!
得点:
これはcode-golfであり、最低バイト数が勝ちです!