Created
April 13, 2014 02:50
-
-
Save 123jimin/10566978 to your computer and use it in GitHub Desktop.
Google Codejam Qualification Round 2014 / Magic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* I studied COBOL for a week... :( | |
Identification Division. | |
Program-Id. Codejam-Qualification-A. | |
Author. Jimin Park. | |
Data Division. | |
Working-Storage Section. | |
01 T PIC 999 Value ZEROS. | |
01 i PIC 99 Value ZEROS. | |
01 j PIC 99 Value ZEROS. | |
01 Ti PIC 999 Value ZEROS. | |
01 Di PIC 9 Value ZERO. | |
01 Li PIC 9 Value ZERO. | |
01 InLine PIC X(11) Value SPACES. | |
01 Row1i PIC 9 Value ZERO. | |
01 Row2i PIC 9 Value ZERO. | |
01 Row1Table. | |
02 Row1 Occurs 4 Times PIC 99. | |
01 Row2Table. | |
02 Row2 Occurs 4 Times PIC 99. | |
01 Tmp PIC 99 Value ZEROS. | |
* I know this is shitty... :( | |
01 Tmp1 PIC 99 Value ZEROS. | |
01 Tmp2 PIC 99 Value ZEROS. | |
01 Tmp3 PIC 99 Value ZEROS. | |
01 Tmp4 PIC 99 Value ZEROS. | |
01 EqC PIC 99 Value ZEROS. | |
01 SN PIC 99 Value ZEROS. | |
01 BoardTable. | |
02 Board Occurs 16 Times PIC 99. | |
Procedure Division. | |
Main. | |
Accept T. | |
Perform Varying Ti From 1 By 1 Until Ti > T | |
Move ZEROS to EqC | |
Move ZEROS to SN | |
Accept Row1i | |
Perform Input-Number | |
Varying i From 0 By 1 Until i=4 | |
Perform Varying i From 1 By 1 Until i > 4 | |
Compute Tmp = Row1i*4 + i - 4 | |
Move Board(Tmp) To Row1(i) | |
End-Perform | |
Accept Row2i | |
Perform Input-Number | |
Varying i From 0 By 1 Until i=4 | |
Perform Varying i From 1 By 1 Until i > 4 | |
Compute Tmp = Row2i*4 + i - 4 | |
Move Board(Tmp) To Row2(i) | |
End-Perform | |
Perform Check-Equal | |
Varying i From 1 By 1 Until i > 4 | |
After j From 1 By 1 Until j > 4 | |
Perform Varying Di From 1 By 1 | |
Until Di >= Length of Ti or Ti(Di:1) not = '0' | |
End-Perform | |
Compute Li = Length of Ti + 1 - Di | |
Perform Display-Message | |
End-Perform. | |
Stop Run. | |
Input-Number. | |
Accept InLine. | |
Multiply i By 4 Giving Tmp. | |
Add Tmp To 1 Giving Tmp1. | |
Add Tmp To 2 Giving Tmp2. | |
Add Tmp To 3 Giving Tmp3. | |
Add Tmp To 4 Giving Tmp4. | |
Unstring InLine Delimited By All SPACES | |
Into Board(Tmp1), Board(Tmp2), | |
Board(Tmp3), Board(Tmp4) | |
End-Unstring. | |
Check-Equal. | |
If Row1(i) equal Row2(j) Then | |
Add 1 To EqC | |
Move Row1(i) to SN | |
End-If. | |
Display-Message. | |
Evaluate EqC | |
When 0 | |
Display "Case #" Ti(Di:Li) ": Volunteer cheated!" | |
When 1 | |
If SN > 9 Then | |
Display "Case #" Ti(Di:Li) ": " SN | |
Else | |
Display "Case #" Ti(Di:Li) ": " SN(2:1) | |
End-If | |
When Other | |
Display "Case #" Ti(Di:Li) ": Bad magician!" | |
End-Evaluate. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment