WeixiangYan/CodeTransOcean huggingface dataset:
Task: Ordered words


C++: #include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>

bool ordered(const std::string &word)
{
    return std::is_sorted(word.begin(), word.end()); 
}

int main()
{
    std::ifstream infile("unixdict.txt");
    if (!infile) {
        std::cerr << "Can't open word file\n";
        return -1;
    }

    std::vector<std::string> words;
    std::string word;
    int longest = 0;

    while (std::getline(infile, word)) {
        int length = word.length();
        if (length < longest) continue; 
        
        if (ordered(word)) {
            if (longest < length) {
                longest = length; 
                words.clear(); 
            }
            words.push_back(word);
        }
    }
    std::copy(words.begin(), words.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
}









Fortran: 
 module ordered_module

 implicit none 

	
	integer,parameter :: file_unit = 1000
	character(len=*),parameter :: filename = 'unixdict.txt'

	
	integer,parameter :: max_chars = 50

	type word 
	  character(len=max_chars) :: str    
	  integer	:: n = 0    
	  logical	:: ordered = .false.    
	end type word
 
	
	type(word),dimension(:),allocatable :: dict
 
	contains

 
	
		function count_lines_in_file(fid) result(n_lines)
	
		implicit none
 
		integer             :: n_lines
		integer,intent(in)  :: fid		
		character(len=1)    :: tmp
		integer             :: i
		integer             :: ios
 
		
 
		rewind(fid)	  
 
		n_lines = 0
		do 
			read(fid,'(A1)',iostat=ios) tmp
			if (ios < 0) exit      
			n_lines = n_lines + 1  
		end do
 
		rewind(fid)   
 
	
		end function count_lines_in_file
	

	
	 pure elemental function ordered_word(word) result(yn)
	
	
	
	 
	 implicit none
	 character(len=*),intent(in) :: word
	 logical :: yn
	 
	 integer :: i
	 
	 yn = .true.
	 do i=1,len_trim(word)-1
	 	if (ichar(word(i+1:i+1))<ichar(word(i:i))) then
	 		yn = .false.
	 		exit
	 	end if
	 end do
	 
	
	 end function ordered_word
	
 

 end module ordered_module



 program main

 use ordered_module
 implicit none

	integer :: i,n,n_max
 
	
	open(unit=file_unit,file=filename)     		
	n = count_lines_in_file(file_unit)      
	allocate(dict(n))                       
	do i=1,n                                
		read(file_unit,'(A)') dict(i)%str   
		dict(i)%n = len_trim(dict(i)%str)   
	end do		
	close(file_unit)                        

	
	dict%ordered = ordered_word(dict%str)	

	
	n_max = maxval(dict%n, mask=dict%ordered)
		
	
	do i=1,n
		if (dict(i)%ordered .and. dict(i)%n==n_max) write(*,'(A,A)',advance='NO') trim(dict(i)%str),' '
	end do
	write(*,*) ''


 end program main
Task: Ordered words





Java: import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

public class Ordered {

	private static boolean isOrderedWord(String word){
		char[] sortedWord = word.toCharArray();
		Arrays.sort(sortedWord);
		return word.equals(new String(sortedWord));
	}
	
	public static void main(String[] args) throws IOException{
		List<String> orderedWords = new LinkedList<String>();
		BufferedReader in = new BufferedReader(new FileReader(args[0]));
		while(in.ready()){
			String word = in.readLine();
			if(isOrderedWord(word)) orderedWords.add(word);
		}
		in.close();
		
		Collections.<String>sort(orderedWords, new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				return new Integer(o2.length()).compareTo(o1.length());
			}
		});
		
		int maxLen = orderedWords.get(0).length();
		for(String word: orderedWords){
			if(word.length() == maxLen){
				System.out.println(word);
			}else{
				break;
			}
		}
	}
}






Fortran: 
 module ordered_module

 implicit none 

	
	integer,parameter :: file_unit = 1000
	character(len=*),parameter :: filename = 'unixdict.txt'

	
	integer,parameter :: max_chars = 50

	type word 
	  character(len=max_chars) :: str    
	  integer	:: n = 0    
	  logical	:: ordered = .false.    
	end type word
 
	
	type(word),dimension(:),allocatable :: dict
 
	contains

 
	
		function count_lines_in_file(fid) result(n_lines)
	
		implicit none
 
		integer             :: n_lines
		integer,intent(in)  :: fid		
		character(len=1)    :: tmp
		integer             :: i
		integer             :: ios
 
		
 
		rewind(fid)	  
 
		n_lines = 0
		do 
			read(fid,'(A1)',iostat=ios) tmp
			if (ios < 0) exit      
			n_lines = n_lines + 1  
		end do
 
		rewind(fid)   
 
	
		end function count_lines_in_file
	

	
	 pure elemental function ordered_word(word) result(yn)
	
	
	
	 
	 implicit none
	 character(len=*),intent(in) :: word
	 logical :: yn
	 
	 integer :: i
	 
	 yn = .true.
	 do i=1,len_trim(word)-1
	 	if (ichar(word(i+1:i+1))<ichar(word(i:i))) then
	 		yn = .false.
	 		exit
	 	end if
	 end do
	 
	
	 end function ordered_word
	
 

 end module ordered_module



 program main

 use ordered_module
 implicit none

	integer :: i,n,n_max
 
	
	open(unit=file_unit,file=filename)     		
	n = count_lines_in_file(file_unit)      
	allocate(dict(n))                       
	do i=1,n                                
		read(file_unit,'(A)') dict(i)%str   
		dict(i)%n = len_trim(dict(i)%str)   
	end do		
	close(file_unit)                        

	
	dict%ordered = ordered_word(dict%str)	

	
	n_max = maxval(dict%n, mask=dict%ordered)
		
	
	do i=1,n
		if (dict(i)%ordered .and. dict(i)%n==n_max) write(*,'(A,A)',advance='NO') trim(dict(i)%str),' '
	end do
	write(*,*) ''


 end program main
Task: Ordered words







Python: import urllib.request

url = 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
words = urllib.request.urlopen(url).read().decode("utf-8").split()
ordered = [word for word in words if word==''.join(sorted(word))]
maxlen = len(max(ordered, key=len))
maxorderedwords = [word for word in ordered if len(word) == maxlen]
print(' '.join(maxorderedwords))




Fortran: 
 module ordered_module

 implicit none 

	
	integer,parameter :: file_unit = 1000
	character(len=*),parameter :: filename = 'unixdict.txt'

	
	integer,parameter :: max_chars = 50

	type word 
	  character(len=max_chars) :: str    
	  integer	:: n = 0    
	  logical	:: ordered = .false.    
	end type word
 
	
	type(word),dimension(:),allocatable :: dict
 
	contains

 
	
		function count_lines_in_file(fid) result(n_lines)
	
		implicit none
 
		integer             :: n_lines
		integer,intent(in)  :: fid		
		character(len=1)    :: tmp
		integer             :: i
		integer             :: ios
 
		
 
		rewind(fid)	  
 
		n_lines = 0
		do 
			read(fid,'(A1)',iostat=ios) tmp
			if (ios < 0) exit      
			n_lines = n_lines + 1  
		end do
 
		rewind(fid)   
 
	
		end function count_lines_in_file
	

	
	 pure elemental function ordered_word(word) result(yn)
	
	
	
	 
	 implicit none
	 character(len=*),intent(in) :: word
	 logical :: yn
	 
	 integer :: i
	 
	 yn = .true.
	 do i=1,len_trim(word)-1
	 	if (ichar(word(i+1:i+1))<ichar(word(i:i))) then
	 		yn = .false.
	 		exit
	 	end if
	 end do
	 
	
	 end function ordered_word
	
 

 end module ordered_module



 program main

 use ordered_module
 implicit none

	integer :: i,n,n_max
 
	
	open(unit=file_unit,file=filename)     		
	n = count_lines_in_file(file_unit)      
	allocate(dict(n))                       
	do i=1,n                                
		read(file_unit,'(A)') dict(i)%str   
		dict(i)%n = len_trim(dict(i)%str)   
	end do		
	close(file_unit)                        

	
	dict%ordered = ordered_word(dict%str)	

	
	n_max = maxval(dict%n, mask=dict%ordered)
		
	
	do i=1,n
		if (dict(i)%ordered .and. dict(i)%n==n_max) write(*,'(A,A)',advance='NO') trim(dict(i)%str),' '
	end do
	write(*,*) ''


 end program main
Task: Ordered words








VB: Set objFSO = CreateObject("Scripting.FileSystemObject")
Set infile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" &_
			"unixdict.txt",1)
list = ""
length = 0

Do Until inFile.AtEndOfStream
	line = infile.ReadLine
	If IsOrdered(line) Then
		If Len(line) > length Then
			length = Len(line)
			list = line & vbCrLf
		ElseIf Len(line) = length Then
			list = list & line & vbCrLf
		End If
	End If
Loop

WScript.StdOut.Write list

Function IsOrdered(word)
	IsOrdered = True
	prev_val = 0
	For i = 1 To Len(word)
		If i = 1 Then
			prev_val = Asc(Mid(word,i,1))
		ElseIf Asc(Mid(word,i,1)) >= prev_val Then
			prev_val = Asc(Mid(word,i,1))
		Else
			IsOrdered = False
			Exit For
		End If
	Next
End Function



Fortran: 
 module ordered_module

 implicit none 

	
	integer,parameter :: file_unit = 1000
	character(len=*),parameter :: filename = 'unixdict.txt'

	
	integer,parameter :: max_chars = 50

	type word 
	  character(len=max_chars) :: str    
	  integer	:: n = 0    
	  logical	:: ordered = .false.    
	end type word
 
	
	type(word),dimension(:),allocatable :: dict
 
	contains

 
	
		function count_lines_in_file(fid) result(n_lines)
	
		implicit none
 
		integer             :: n_lines
		integer,intent(in)  :: fid		
		character(len=1)    :: tmp
		integer             :: i
		integer             :: ios
 
		
 
		rewind(fid)	  
 
		n_lines = 0
		do 
			read(fid,'(A1)',iostat=ios) tmp
			if (ios < 0) exit      
			n_lines = n_lines + 1  
		end do
 
		rewind(fid)   
 
	
		end function count_lines_in_file
	

	
	 pure elemental function ordered_word(word) result(yn)
	
	
	
	 
	 implicit none
	 character(len=*),intent(in) :: word
	 logical :: yn
	 
	 integer :: i
	 
	 yn = .true.
	 do i=1,len_trim(word)-1
	 	if (ichar(word(i+1:i+1))<ichar(word(i:i))) then
	 		yn = .false.
	 		exit
	 	end if
	 end do
	 
	
	 end function ordered_word
	
 

 end module ordered_module



 program main

 use ordered_module
 implicit none

	integer :: i,n,n_max
 
	
	open(unit=file_unit,file=filename)     		
	n = count_lines_in_file(file_unit)      
	allocate(dict(n))                       
	do i=1,n                                
		read(file_unit,'(A)') dict(i)%str   
		dict(i)%n = len_trim(dict(i)%str)   
	end do		
	close(file_unit)                        

	
	dict%ordered = ordered_word(dict%str)	

	
	n_max = maxval(dict%n, mask=dict%ordered)
		
	
	do i=1,n
		if (dict(i)%ordered .and. dict(i)%n==n_max) write(*,'(A,A)',advance='NO') trim(dict(i)%str),' '
	end do
	write(*,*) ''


 end program main
Task: Ordered words



C#: using System;
using System.Linq;
using System.Net;

static class Program
{
    static void Main(string[] args)
    {
        WebClient client = new WebClient();
        string text = client.DownloadString("http:
        string[] words = text.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);

        var query = from w in words
                    where IsOrderedWord(w)
                    group w by w.Length into ows
                    orderby ows.Key descending
                    select ows;

        Console.WriteLine(string.Join(", ", query.First().ToArray()));
    }

    private static bool IsOrderedWord(string w)
    {
        for (int i = 1; i < w.Length; i++)
            if (w[i] < w[i - 1])
                return false;

        return true;
    }
}







COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC-WORDS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 ENTRY.
          03 WORD         PIC X(32).
          03 LETTERS      PIC X OCCURS 32 TIMES, REDEFINES WORD.
       
       WORKING-STORAGE SECTION.
       01 LEN             PIC 99.
       01 MAXLEN          PIC 99 VALUE 0.
       01 I               PIC 99.
       01 OK-FLAG         PIC X.
          88 OK           VALUE '*'.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       FIND-LONGEST-WORD.
           READ DICT, AT END CLOSE DICT, GO TO PRINT-LONGEST-WORDS.
           PERFORM CHECK-WORD.
           GO TO FIND-LONGEST-WORD.
           
       PRINT-LONGEST-WORDS.
           ALTER VALID-WORD TO PROCEED TO SHOW-WORD.
           OPEN INPUT DICT.
       
       READ-WORDS.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORDS.
           
       CHECK-WORD.
           MOVE ZERO TO LEN.
           INSPECT WORD TALLYING LEN 
               FOR CHARACTERS BEFORE INITIAL SPACE.
           MOVE '*' TO OK-FLAG.
           PERFORM CHECK-CHAR-PAIR VARYING I FROM 2 BY 1
               UNTIL NOT OK OR I IS GREATER THAN LEN.
           IF OK, PERFORM DO-WORD.
       
       CHECK-CHAR-PAIR.
           IF LETTERS(I - 1) IS GREATER THAN LETTERS(I), 
               MOVE SPACE TO OK-FLAG.
         
       DO-WORD SECTION.         
       VALID-WORD.
           GO TO CHECK-LENGTH.
       CHECK-LENGTH.
           IF LEN IS GREATER THAN MAXLEN, MOVE LEN TO MAXLEN.
           GO TO DONE.
       SHOW-WORD.
           IF LEN IS EQUAL TO MAXLEN, DISPLAY WORD.
       DONE.
           EXIT.
Task: Ordered words


C++: #include <algorithm>
#include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>

bool ordered(const std::string &word)
{
    return std::is_sorted(word.begin(), word.end()); 
}

int main()
{
    std::ifstream infile("unixdict.txt");
    if (!infile) {
        std::cerr << "Can't open word file\n";
        return -1;
    }

    std::vector<std::string> words;
    std::string word;
    int longest = 0;

    while (std::getline(infile, word)) {
        int length = word.length();
        if (length < longest) continue; 
        
        if (ordered(word)) {
            if (longest < length) {
                longest = length; 
                words.clear(); 
            }
            words.push_back(word);
        }
    }
    std::copy(words.begin(), words.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC-WORDS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 ENTRY.
          03 WORD         PIC X(32).
          03 LETTERS      PIC X OCCURS 32 TIMES, REDEFINES WORD.
       
       WORKING-STORAGE SECTION.
       01 LEN             PIC 99.
       01 MAXLEN          PIC 99 VALUE 0.
       01 I               PIC 99.
       01 OK-FLAG         PIC X.
          88 OK           VALUE '*'.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       FIND-LONGEST-WORD.
           READ DICT, AT END CLOSE DICT, GO TO PRINT-LONGEST-WORDS.
           PERFORM CHECK-WORD.
           GO TO FIND-LONGEST-WORD.
           
       PRINT-LONGEST-WORDS.
           ALTER VALID-WORD TO PROCEED TO SHOW-WORD.
           OPEN INPUT DICT.
       
       READ-WORDS.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORDS.
           
       CHECK-WORD.
           MOVE ZERO TO LEN.
           INSPECT WORD TALLYING LEN 
               FOR CHARACTERS BEFORE INITIAL SPACE.
           MOVE '*' TO OK-FLAG.
           PERFORM CHECK-CHAR-PAIR VARYING I FROM 2 BY 1
               UNTIL NOT OK OR I IS GREATER THAN LEN.
           IF OK, PERFORM DO-WORD.
       
       CHECK-CHAR-PAIR.
           IF LETTERS(I - 1) IS GREATER THAN LETTERS(I), 
               MOVE SPACE TO OK-FLAG.
         
       DO-WORD SECTION.         
       VALID-WORD.
           GO TO CHECK-LENGTH.
       CHECK-LENGTH.
           IF LEN IS GREATER THAN MAXLEN, MOVE LEN TO MAXLEN.
           GO TO DONE.
       SHOW-WORD.
           IF LEN IS EQUAL TO MAXLEN, DISPLAY WORD.
       DONE.
           EXIT.
Task: Ordered words





Java: import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;

public class Ordered {

	private static boolean isOrderedWord(String word){
		char[] sortedWord = word.toCharArray();
		Arrays.sort(sortedWord);
		return word.equals(new String(sortedWord));
	}
	
	public static void main(String[] args) throws IOException{
		List<String> orderedWords = new LinkedList<String>();
		BufferedReader in = new BufferedReader(new FileReader(args[0]));
		while(in.ready()){
			String word = in.readLine();
			if(isOrderedWord(word)) orderedWords.add(word);
		}
		in.close();
		
		Collections.<String>sort(orderedWords, new Comparator<String>() {
			@Override
			public int compare(String o1, String o2) {
				return new Integer(o2.length()).compareTo(o1.length());
			}
		});
		
		int maxLen = orderedWords.get(0).length();
		for(String word: orderedWords){
			if(word.length() == maxLen){
				System.out.println(word);
			}else{
				break;
			}
		}
	}
}





COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC-WORDS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 ENTRY.
          03 WORD         PIC X(32).
          03 LETTERS      PIC X OCCURS 32 TIMES, REDEFINES WORD.
       
       WORKING-STORAGE SECTION.
       01 LEN             PIC 99.
       01 MAXLEN          PIC 99 VALUE 0.
       01 I               PIC 99.
       01 OK-FLAG         PIC X.
          88 OK           VALUE '*'.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       FIND-LONGEST-WORD.
           READ DICT, AT END CLOSE DICT, GO TO PRINT-LONGEST-WORDS.
           PERFORM CHECK-WORD.
           GO TO FIND-LONGEST-WORD.
           
       PRINT-LONGEST-WORDS.
           ALTER VALID-WORD TO PROCEED TO SHOW-WORD.
           OPEN INPUT DICT.
       
       READ-WORDS.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORDS.
           
       CHECK-WORD.
           MOVE ZERO TO LEN.
           INSPECT WORD TALLYING LEN 
               FOR CHARACTERS BEFORE INITIAL SPACE.
           MOVE '*' TO OK-FLAG.
           PERFORM CHECK-CHAR-PAIR VARYING I FROM 2 BY 1
               UNTIL NOT OK OR I IS GREATER THAN LEN.
           IF OK, PERFORM DO-WORD.
       
       CHECK-CHAR-PAIR.
           IF LETTERS(I - 1) IS GREATER THAN LETTERS(I), 
               MOVE SPACE TO OK-FLAG.
         
       DO-WORD SECTION.         
       VALID-WORD.
           GO TO CHECK-LENGTH.
       CHECK-LENGTH.
           IF LEN IS GREATER THAN MAXLEN, MOVE LEN TO MAXLEN.
           GO TO DONE.
       SHOW-WORD.
           IF LEN IS EQUAL TO MAXLEN, DISPLAY WORD.
       DONE.
           EXIT.
Task: Ordered words







Python: import urllib.request

url = 'http://www.puzzlers.org/pub/wordlists/unixdict.txt'
words = urllib.request.urlopen(url).read().decode("utf-8").split()
ordered = [word for word in words if word==''.join(sorted(word))]
maxlen = len(max(ordered, key=len))
maxorderedwords = [word for word in ordered if len(word) == maxlen]
print(' '.join(maxorderedwords))



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC-WORDS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 ENTRY.
          03 WORD         PIC X(32).
          03 LETTERS      PIC X OCCURS 32 TIMES, REDEFINES WORD.
       
       WORKING-STORAGE SECTION.
       01 LEN             PIC 99.
       01 MAXLEN          PIC 99 VALUE 0.
       01 I               PIC 99.
       01 OK-FLAG         PIC X.
          88 OK           VALUE '*'.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       FIND-LONGEST-WORD.
           READ DICT, AT END CLOSE DICT, GO TO PRINT-LONGEST-WORDS.
           PERFORM CHECK-WORD.
           GO TO FIND-LONGEST-WORD.
           
       PRINT-LONGEST-WORDS.
           ALTER VALID-WORD TO PROCEED TO SHOW-WORD.
           OPEN INPUT DICT.
       
       READ-WORDS.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORDS.
           
       CHECK-WORD.
           MOVE ZERO TO LEN.
           INSPECT WORD TALLYING LEN 
               FOR CHARACTERS BEFORE INITIAL SPACE.
           MOVE '*' TO OK-FLAG.
           PERFORM CHECK-CHAR-PAIR VARYING I FROM 2 BY 1
               UNTIL NOT OK OR I IS GREATER THAN LEN.
           IF OK, PERFORM DO-WORD.
       
       CHECK-CHAR-PAIR.
           IF LETTERS(I - 1) IS GREATER THAN LETTERS(I), 
               MOVE SPACE TO OK-FLAG.
         
       DO-WORD SECTION.         
       VALID-WORD.
           GO TO CHECK-LENGTH.
       CHECK-LENGTH.
           IF LEN IS GREATER THAN MAXLEN, MOVE LEN TO MAXLEN.
           GO TO DONE.
       SHOW-WORD.
           IF LEN IS EQUAL TO MAXLEN, DISPLAY WORD.
       DONE.
           EXIT.
Task: Ordered words








VB: Set objFSO = CreateObject("Scripting.FileSystemObject")
Set infile = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\" &_
			"unixdict.txt",1)
list = ""
length = 0

Do Until inFile.AtEndOfStream
	line = infile.ReadLine
	If IsOrdered(line) Then
		If Len(line) > length Then
			length = Len(line)
			list = line & vbCrLf
		ElseIf Len(line) = length Then
			list = list & line & vbCrLf
		End If
	End If
Loop

WScript.StdOut.Write list

Function IsOrdered(word)
	IsOrdered = True
	prev_val = 0
	For i = 1 To Len(word)
		If i = 1 Then
			prev_val = Asc(Mid(word,i,1))
		ElseIf Asc(Mid(word,i,1)) >= prev_val Then
			prev_val = Asc(Mid(word,i,1))
		Else
			IsOrdered = False
			Exit For
		End If
	Next
End Function


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC-WORDS.
       
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.
       FILE-CONTROL.
           SELECT DICT ASSIGN TO DISK
           ORGANIZATION LINE SEQUENTIAL.
           
       DATA DIVISION.
       FILE SECTION.
       FD DICT 
           LABEL RECORD STANDARD
           VALUE OF FILE-ID IS "unixdict.txt".
       01 ENTRY.
          03 WORD         PIC X(32).
          03 LETTERS      PIC X OCCURS 32 TIMES, REDEFINES WORD.
       
       WORKING-STORAGE SECTION.
       01 LEN             PIC 99.
       01 MAXLEN          PIC 99 VALUE 0.
       01 I               PIC 99.
       01 OK-FLAG         PIC X.
          88 OK           VALUE '*'.
       
       PROCEDURE DIVISION.
       BEGIN.
           OPEN INPUT DICT.
           
       FIND-LONGEST-WORD.
           READ DICT, AT END CLOSE DICT, GO TO PRINT-LONGEST-WORDS.
           PERFORM CHECK-WORD.
           GO TO FIND-LONGEST-WORD.
           
       PRINT-LONGEST-WORDS.
           ALTER VALID-WORD TO PROCEED TO SHOW-WORD.
           OPEN INPUT DICT.
       
       READ-WORDS.
           READ DICT, AT END CLOSE DICT, STOP RUN.
           PERFORM CHECK-WORD.
           GO TO READ-WORDS.
           
       CHECK-WORD.
           MOVE ZERO TO LEN.
           INSPECT WORD TALLYING LEN 
               FOR CHARACTERS BEFORE INITIAL SPACE.
           MOVE '*' TO OK-FLAG.
           PERFORM CHECK-CHAR-PAIR VARYING I FROM 2 BY 1
               UNTIL NOT OK OR I IS GREATER THAN LEN.
           IF OK, PERFORM DO-WORD.
       
       CHECK-CHAR-PAIR.
           IF LETTERS(I - 1) IS GREATER THAN LETTERS(I), 
               MOVE SPACE TO OK-FLAG.
         
       DO-WORD SECTION.         
       VALID-WORD.
           GO TO CHECK-LENGTH.
       CHECK-LENGTH.
           IF LEN IS GREATER THAN MAXLEN, MOVE LEN TO MAXLEN.
           GO TO DONE.
       SHOW-WORD.
           IF LEN IS EQUAL TO MAXLEN, DISPLAY WORD.
       DONE.
           EXIT.