-
Notifications
You must be signed in to change notification settings - Fork 0
/
day1.cbl
97 lines (90 loc) · 2.49 KB
/
day1.cbl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
IDENTIFICATION DIVISION. *> Compile and run with cobc -std=cobol2014 --free -x day1.cbl -j
PROGRAM-ID. DAY1.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT DAY1DATA ASSIGN TO INPUT
ORGANIZATION IS LINE SEQUENTIAL.
SELECT DAY1SORTLEFT ASSIGN TO DAY1SORTLEFT
ORGANIZATION IS LINE SEQUENTIAL.
SELECT WORKFILE ASSIGN TO WORK1.
SELECT DAY1SORTRIGHT ASSIGN TO DAY1SORTRIGHT
ORGANIZATION IS LINE SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
SD WORKFILE.
01 ENTRY.
05 LEFTCW PIC 9(5).
05 SPCW PIC X(3).
05 RIGHTCW PIC 9(5).
FD DAY1SORTLEFT.
01 ENTRY.
05 LEFTCSL PIC 9(5).
05 SPCSL PIC X(3).
05 RIGHTCSL PIC 9(5).
FD DAY1SORTRIGHT.
01 ENTRY.
05 LEFTCSR PIC 9(5).
05 SPCSR PIC X(3).
05 RIGHTCSR PIC 9(5).
FD DAY1DATA.
01 ENTRY.
05 LEFTC PIC 9(5).
05 SPC PIC X(3).
05 RIGHTC PIC 9(5).
WORKING-STORAGE SECTION.
77 WS-EOF PIC A VALUE 'N'.
88 WS-DONE VALUE 'Y'.
77 WS-EOF-SIM PIC A VALUE 'N'.
88 WS-DONE-SIM VALUE 'Y'.
77 WS-DISTANCE PIC 9(11).
77 WS-TOTAL PIC 9(11).
77 WS-SIMILARITY PIC 9(11).
77 WS-COUNT PIC 9(4).
77 WS-TOCOUNT PIC 9(5).
PROCEDURE DIVISION.
MAIN-PARA.
MOVE ZEROS TO WS-TOTAL.
MOVE ZEROS TO WS-SIMILARITY.
SORT WORKFILE
ON ASCENDING KEY LEFTC
USING DAY1DATA
GIVING DAY1SORTLEFT.
SORT WORKFILE
ON ASCENDING KEY RIGHTC
USING DAY1DATA
GIVING DAY1SORTRIGHT.
OPEN INPUT DAY1SORTLEFT.
OPEN INPUT DAY1SORTRIGHT.
PERFORM UNTIL WS-DONE
READ DAY1SORTLEFT
AT END SET WS-DONE TO TRUE
NOT AT END
READ DAY1SORTRIGHT
NOT AT END
SUBTRACT LEFTCSL FROM RIGHTCSR GIVING WS-DISTANCE
ADD WS-DISTANCE TO WS-TOTAL
MOVE LEFTCSL TO WS-TOCOUNT
PERFORM COUNT-RIGHT-PARA
END-READ
END-PERFORM.
CLOSE DAY1SORTLEFT.
CLOSE DAY1SORTRIGHT.
DISPLAY "TOTAL: " WS-TOTAL
DISPLAY "SIMILARITY: " WS-SIMILARITY
STOP RUN.
COUNT-RIGHT-PARA.
MOVE ZEROS TO WS-COUNT.
OPEN INPUT DAY1DATA.
SET WS-EOF-SIM TO 'N'
PERFORM UNTIL WS-DONE-SIM
READ DAY1DATA
AT END SET WS-DONE-SIM TO TRUE
NOT AT END
IF (RIGHTC EQUAL TO WS-TOCOUNT)
ADD 1 TO WS-COUNT
END-IF
END-READ
END-PERFORM.
CLOSE DAY1DATA.
COMPUTE WS-SIMILARITY = WS-SIMILARITY + (WS-COUNT * WS-TOCOUNT).