いろいろ勉強不足でした、クソダサコードしか書けませんでした。
こんなウンコードをご覧頂いて恐縮です。
こちらhttps://paiza.jp/poh/andoにてウンコードを投げてました。paiza様、楽しいゲームありがとうございます。
一応レアアイテム以外はコンプしましたが、正直人様に見せるには恥ずかしすぎるレベルです。
「それでも」と言う大先輩方、アドバイスよろしくお願いします…
※下記のコードでアイテム解禁確認済み(使用言語:COBOL)
つり目
IDENTIFICATION DIVISION.
PROGRAM-ID. Slant-eyes.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 IN-NUM PIC 9(2).
01 UNION-X PIC X(30) VALUE "AnnAnnAnnAnnAnnAnnAnnAnnAnnAnn".
PROCEDURE DIVISION.
ACCEPT IN-NUM FROM CONSOLE.
COMPUTE IN-NUM = IN-NUM * 3.
DISPLAY UNION-X (1 : IN-NUM).
STOP-RUN.
今回の中で一番短く書けた。UNION-Xの中身を見るとコーディングした人間のあたまのよわさが伺えます。
###ショートヘア
IDENTIFICATION DIVISION.
PROGRAM-ID. Short-hair.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INPUT-NUM1 PIC 9(3).
01 INPUT-NUM2 PIC 9(3).
01 OUT1 PIC 9(1).
01 OUT2 PIC 9(2).
01 OUT3 PIC 9(3).
PROCEDURE DIVISION.
ACCEPT INPUT-NUM1 FROM CONSOLE.
ACCEPT INPUT-NUM2 FROM CONSOLE.
COMPUTE OUT3 = INPUT-NUM1 + INPUT-NUM2.
IF OUT3 > 99 THEN
DISPLAY OUT3
STOP RUN
END-IF.
IF OUT3 > 9 THEN
MOVE OUT3 TO OUT2
DISPLAY OUT2
STOP RUN
END-IF.
MOVE OUT3 TO OUT1.
DISPLAY OUT1.
STOP-RUN.
桁数の対策がこれしかないとは思えないのだが…
###ロングヘア
IDENTIFICATION DIVISION.
PROGRAM-ID. Long-hair.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 DAT.
03 YL OCCURS 5.
05 INPUT-CHAR PIC X(3).
01 CTP PIC 9(1) VALUE 1.
01 CTY PIC 9(1) VALUE 0.
01 CTN PIC 9(1) VALUE 0.
PROCEDURE DIVISION.
PERFORM UNTIL CTP = 6
ACCEPT INPUT-CHAR(CTP) FROM CONSOLE
IF INPUT-CHAR(CTP) = "yes" THEN
ADD 1 TO CTY
ELSE
ADD 1 TO CTN
END-IF
ADD 1 TO CTP
END-PERFORM.
IF CTY > CTN THEN
DISPLAY "yes"
ELSE
DISPLAY "no"
END-IF.
STOP-RUN.
ただの比較ですがもう少し短くできないものか…
###ポニーテール
IDENTIFICATION DIVISION.
PROGRAM-ID. Pony-tail.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CTP PIC 9(1) VALUE 9.
01 IN1 PIC 9(1) VALUE 0.
01 IN2 PIC 9(2) VALUE 0.
01 IN3 PIC 9(3).
01 FLG PIC 9(1) VALUE 0.
PROCEDURE DIVISION.
ACCEPT IN3 FROM CONSOLE.
IF IN3 = 100 THEN
DISPLAY IN3
MOVE 99 TO IN2
ELSE
MOVE IN3 TO IN2
END-IF.
IF IN3 < 10
MOVE IN3 TO IN1
MOVE 1 TO FLG
END-IF.
IF IN2 > 9 AND IN2 < 100
PERFORM UNTIL CTP = IN2
DISPLAY IN2
COMPUTE IN2 = IN2 - 1
END-PERFORM
MOVE 9 TO IN1
MOVE 0 TO CTP
END-IF.
IF IN1 = 9 AND FLG = 0 THEN
PERFORM UNTIL CTP = IN1
DISPLAY IN1
COMPUTE IN1 = IN1 - 1
END-PERFORM
END-IF
MOVE 0 TO CTP.
IF FLG = 1 THEN
PERFORM UNTIL 0 = IN1
DISPLAY IN1
COMPUTE IN1 = IN1 - 1
END-PERFORM
END-IF.
DISPLAY "0!!".
STOP-RUN.
これぞウンコード、書いた本人ですらよくわからない、読みたくない。
###ツインテール
IDENTIFICATION DIVISION.
PROGRAM-ID. Twin-tail.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 TYPE1.
03 IN-NUM1 PIC X(9).
03 C1-F PIC 9(4).
03 P1-F PIC 9(4).
03 DUST1 PIC X(6).
03 RATIO1 PIC 9(4)V99999999999999.
01 TYPE2.
03 IN-NUM2 PIC X(9).
03 C2-F PIC 9(4).
03 P2-F PIC 9(4).
03 DUST2 PIC X(6).
03 RATIO2 PIC 9(4)V99999999999999.
PROCEDURE DIVISION.
ACCEPT IN-NUM1 FROM CONSOLE.
ACCEPT IN-NUM2 FROM CONSOLE.
UNSTRING
IN-NUM1 DELIMITED BY " " INTO C1-F
P1-F
DUST1
END-UNSTRING.
UNSTRING
IN-NUM2 DELIMITED BY " " INTO C2-F
P2-F
DUST2
END-UNSTRING.
COMPUTE RATIO1 = C1-F / P1-F.
COMPUTE RATIO2 = C2-F / P2-F.
IF RATIO1 > RATIO2 THEN
DISPLAY "1"
ELSE
DISPLAY "2"
END-IF.
STOP-RUN.
STRING句でPOINTERを使いたい人生だった。多分UNSTRING句でオーバーフロー(?)してる。
セーラー服
IDENTIFICATION DIVISION.
PROGRAM-ID. Sera.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 CNT-PER PIC 9(2).
01 INPUT-NUM PIC 9(2).
01 LENG PIC 9(3).
01 UNION-X PIC X(100).
01 DAT.
03 YL OCCURS 10.
05 INPUT-CHAR PIC X(10).
PROCEDURE DIVISION.
ACCEPT INPUT-NUM FROM CONSOLE.
MOVE 1 TO CNT-PER.
ADD 1 TO INPUT-NUM.
PERFORM UNTIL CNT-PER = INPUT-NUM
ACCEPT INPUT-CHAR(CNT-PER)
ADD 1 TO CNT-PER
END-PERFORM.
COMPUTE INPUT-NUM = INPUT-NUM - 1.
EVALUATE INPUT-NUM
WHEN 2
STRING
INPUT-CHAR(1) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(2) DELIMITED BY " "
INTO UNION-X
END-STRING
WHEN 3
STRING
INPUT-CHAR(1) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(2) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(3) DELIMITED BY " "
INTO UNION-X
END-STRING
WHEN 4
STRING
INPUT-CHAR(1) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(2) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(3) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(4) DELIMITED BY " "
INTO UNION-X
END-STRING
WHEN 5
STRING
INPUT-CHAR(1) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(2) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(3) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(4) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(5) DELIMITED BY " "
INTO UNION-X
END-STRING
WHEN 6
STRING
INPUT-CHAR(1) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(2) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(3) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(4) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(5) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(6) DELIMITED BY " "
INTO UNION-X
END-STRING
WHEN 7
STRING
INPUT-CHAR(1) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(2) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(3) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(4) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(5) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(6) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(7) DELIMITED BY " "
INTO UNION-X
END-STRING
WHEN 8
STRING
INPUT-CHAR(1) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(2) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(3) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(4) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(5) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(6) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(7) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(8) DELIMITED BY " "
INTO UNION-X
END-STRING
WHEN 9
STRING
INPUT-CHAR(1) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(2) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(3) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(4) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(5) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(6) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(7) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(8) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(9) DELIMITED BY " "
INTO UNION-X
END-STRING
WHEN 10
STRING
INPUT-CHAR(1) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(2) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(3) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(4) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(5) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(6) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(7) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(8) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(9) DELIMITED BY " "
"_" DELIMITED BY SIZE
INPUT-CHAR(10) DELIMITED BY " "
INTO UNION-X
END-STRING
WHEN OTHER
STRING
"ERROR" DELIMITED BY SIZE
INTO UNION-X
END-STRING
END-EVALUATE.
COMPUTE LENG = FUNCTION STORED-CHAR-LENGTH(UNION-X).
DISPLAY UNION-X (1 : LENG).
STOP-RUN.
ダサくてごめんなさい、冗長でごめんなさい。STRING句でうまくPOINTER使えませんでした許してください。
###カーディガン
IDENTIFICATION DIVISION.
PROGRAM-ID. Cardigan.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INPUT-NUM PIC 9(1).
01 CNT-PER PIC 9(1) VALUE 0.
01 OUT1 PIC 9(1).
01 OUT2 PIC 9(2).
01 OUT3 PIC 9(3).
01 TMP-COMP PIC 9(4) VALUE 1.
PROCEDURE DIVISION.
ACCEPT INPUT-NUM FROM CONSOLE.
PERFORM UNTIL CNT-PER = INPUT-NUM
COMPUTE TMP-COMP = TMP-COMP * INPUT-NUM
COMPUTE INPUT-NUM = INPUT-NUM - 1
END-PERFORM.
IF TMP-COMP > 999 THEN
DISPLAY TMP-COMP
STOP RUN
END-IF.
IF TMP-COMP > 99 THEN
MOVE TMP-COMP TO OUT3
DISPLAY OUT3
STOP RUN
END-IF.
IF TMP-COMP > 9 THEN
MOVE TMP-COMP TO OUT2
DISPLAY OUT2
STOP RUN
END-IF.
MOVE TMP-COMP TO OUT1.
DISPLAY OUT1.
STOP-RUN.
うまく桁数を減らして表示できないものか…
##まとめ
固定長しか扱えないと認識してコーディングしてました。
全体的に同じような変数に値を移動させているのはチェックケースの関係です。
例えば数値3桁の変数に2桁の数値を入れると右揃えになり空いた桁に0が挿入されます。(例:32→032)
このためチェックケースと出力が合わなくて蹴られます。
私はこれを回避するためにMOVEで有効桁分の変数に入れなおす作業をしています。なんとかスマートにできないものか…
見ての通りひどいコードです、応用もへったくれもありません、仕様変更を言われようものなら血涙を流しながら1から書き換えるレベルです。
なんとなく高校でCOBOLを習っていたので興味本位でやりましたがさすがにキツイです。
レアアイテム以外揃っても結局、ワンピースとショートボブ。
一応レアアイテムも挑戦してみますがこの程度のCOBOLの理解度でどこまでいけるものか…
進捗があったら更新します。