WeixiangYan/CodeTransOcean huggingface dataset:
Task: Command-line arguments







Python: import sys
program_name = sys.argv[0]
arguments = sys.argv[1:]
count = len(arguments)



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. accept-all-args.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  args                   PIC X(50).
       
       PROCEDURE DIVISION.
       main-line.
           ACCEPT args FROM COMMAND-LINE
           DISPLAY args
           
           GOBACK
           .
Task: Command-line arguments








VB: Function Run(args() as String) As Integer
  For each arg As String In args
    Stdout.WriteLine(arg)
  Next
End Function


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. accept-all-args.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  args                   PIC X(50).
       
       PROCEDURE DIVISION.
       main-line.
           ACCEPT args FROM COMMAND-LINE
           DISPLAY args
           
           GOBACK
           .
Task: Command-line arguments




Go: package main
import (
	"fmt"
	"os"
)

func main() {
	for i, x := range os.Args[1:] {
		fmt.Printf("the argument #%d is %s\n", i, x)
	}
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. accept-all-args.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  args                   PIC X(50).
       
       PROCEDURE DIVISION.
       main-line.
           ACCEPT args FROM COMMAND-LINE
           DISPLAY args
           
           GOBACK
           .
Task: Command-line arguments






PHP: <?php
$program_name = $argv[0];
$second_arg = $argv[2];
$all_args_without_program_name = array_shift($argv);
Task: Command-line arguments






PHP: <?php
$program_name = $argv[0];
$second_arg = $argv[2];
$all_args_without_program_name = array_shift($argv);






Ada: with Ada.Command_line; use Ada.Command_Line;
with Ada.Text_IO; use Ada.Text_IO;

procedure Print_Commands is
begin
   
   
   
   Put(Command_Name & " ");
   for Arg in 1..Argument_Count loop
      Put(Argument(Arg) & " ");
   end loop;
   New_Line;
end Print_Commands;
Task: Command-line arguments






PHP: <?php
$program_name = $argv[0];
$second_arg = $argv[2];
$all_args_without_program_name = array_shift($argv);




COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. accept-all-args.
       
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01  args                   PIC X(50).
       
       PROCEDURE DIVISION.
       main-line.
           ACCEPT args FROM COMMAND-LINE
           DISPLAY args
           
           GOBACK
           .
Task: Sort the letters of string in alphabetical order



C#: using System; using static System.Console;
class Program {
  static void Main(string[] args) {
    var nl = "\n";
    var omit_spaces = true;
    var str = "forever ring programming language";
    Write( "working..." + nl );
    Write( "Sort the letters of string in alphabitical order:" + nl );
    Write( "Input: " + str + nl );
    Write( "Output: " );
    for (var ch = omit_spaces ? 33 : 0; ch < 256; ch++)
      foreach (var itm in str)
        if (ch == itm) Console.Write(itm);
    Write( nl + "done..." );
  }
}









Ada: with Ada.Text_Io;
with Ada.Containers.Generic_Array_Sort;

procedure Sort_Letters is

   function Compare (Left, Right : Character) return Boolean
   is (Left < Right);

   procedure Sort is new
     Ada.Containers.Generic_Array_Sort (Index_Type   => Positive,
                                        Element_Type => Character,
                                        Array_Type   => String,
                                        "<"          => Compare);

   use Ada.Text_Io;
   B : String := "When Roman engineers built a bridge, they had to stand under it while the first legion marched across. If programmers today worked under similar ground rules, they might well find themselves getting much more interested in Ada!";

begin
   Put_Line (B); Sort (B); Put_Line (B);
end Sort_Letters;
Task: Sort the letters of string in alphabetical order

C: #include <stdio.h>


void strsort(char *s) {
    unsigned int n[256] = {0};
    unsigned char i = 0;
    char *t = s;
    while (*s) ++n[(unsigned char) *s++];
    while (++i) while (n[i]--) *t++ = (char) i;
}

int main() {
    char s[] = "Now is the time for all good men "
               "to come to the aid of their country.";
    puts(s);
    strsort(s);
    puts(s);
    return 0;
}











Ada: with Ada.Text_Io;
with Ada.Containers.Generic_Array_Sort;

procedure Sort_Letters is

   function Compare (Left, Right : Character) return Boolean
   is (Left < Right);

   procedure Sort is new
     Ada.Containers.Generic_Array_Sort (Index_Type   => Positive,
                                        Element_Type => Character,
                                        Array_Type   => String,
                                        "<"          => Compare);

   use Ada.Text_Io;
   B : String := "When Roman engineers built a bridge, they had to stand under it while the first legion marched across. If programmers today worked under similar ground rules, they might well find themselves getting much more interested in Ada!";

begin
   Put_Line (B); Sort (B); Put_Line (B);
end Sort_Letters;
Task: Sort the letters of string in alphabetical order


C++: #include <algorithm>
#include <iostream>

int main() {
    std::string s = "Now is the time for all good men "
                    "to come to the aid of our country.";
    
    std::cout << s << std::endl;
    std::sort(s.begin(), s.end());
    std::cout << s << std::endl; 
    return 0;
}










Ada: with Ada.Text_Io;
with Ada.Containers.Generic_Array_Sort;

procedure Sort_Letters is

   function Compare (Left, Right : Character) return Boolean
   is (Left < Right);

   procedure Sort is new
     Ada.Containers.Generic_Array_Sort (Index_Type   => Positive,
                                        Element_Type => Character,
                                        Array_Type   => String,
                                        "<"          => Compare);

   use Ada.Text_Io;
   B : String := "When Roman engineers built a bridge, they had to stand under it while the first legion marched across. If programmers today worked under similar ground rules, they might well find themselves getting much more interested in Ada!";

begin
   Put_Line (B); Sort (B); Put_Line (B);
end Sort_Letters;
Task: Sort the letters of string in alphabetical order




Go: package main

import (
    "fmt"
    "strings"
)

func bubbleSort(s string, trim bool) string { 
    chars := []rune(s)
    n := len(chars)
    for {
        n2 := 0
        for i := 1; i < n; i++ {
            if chars[i-1] > chars[i] {
                tmp := chars[i]
                chars[i] = chars[i-1]
                chars[i-1] = tmp
                n2 = i
            }
        }
        n = n2
        if n == 0 {
            break
        }
    }
    s = string(chars)
    if trim {
        s = strings.TrimLeft(s, " \t\r\n")
    }
    return s
}

func main() {
    ss := []string{
        "forever go programming language",
        "Now is the time for all good men to come to the aid of their country.",
    }
    trims := []bool{true, false}
    for i, s := range ss {
        res := bubbleSort(s, trims[i])
        fmt.Printf("Unsorted->%s\n", s)
        fmt.Printf("Sorted  ->%s\n\n", res)
    }
}








Ada: with Ada.Text_Io;
with Ada.Containers.Generic_Array_Sort;

procedure Sort_Letters is

   function Compare (Left, Right : Character) return Boolean
   is (Left < Right);

   procedure Sort is new
     Ada.Containers.Generic_Array_Sort (Index_Type   => Positive,
                                        Element_Type => Character,
                                        Array_Type   => String,
                                        "<"          => Compare);

   use Ada.Text_Io;
   B : String := "When Roman engineers built a bridge, they had to stand under it while the first legion marched across. If programmers today worked under similar ground rules, they might well find themselves getting much more interested in Ada!";

begin
   Put_Line (B); Sort (B); Put_Line (B);
end Sort_Letters;
Task: Sort the letters of string in alphabetical order







Python: 

from functools import reduce



def qSort(xs):
    
    if xs:
        h = xs[0]
        below, above = partition(
            lambda v: v <= h
        )(xs[1:])

        return qSort(below) + [h] + qSort(above)
    else:
        return []



def main():
    
    print(quoted('"')(
        ''.join(qSort(list(
            "Is this misspelling of alphabetical as alphabitical a joke ?"
        )))
    ))





def partition(p):
    
    def go(a, x):
        ts, fs = a
        return (ts + [x], fs) if p(x) else (ts, fs + [x])
    return lambda xs: reduce(go, xs, ([], []))



def quoted(c):
    
    return lambda s: c + s + c



if __name__ == '__main__':
    main()





Ada: with Ada.Text_Io;
with Ada.Containers.Generic_Array_Sort;

procedure Sort_Letters is

   function Compare (Left, Right : Character) return Boolean
   is (Left < Right);

   procedure Sort is new
     Ada.Containers.Generic_Array_Sort (Index_Type   => Positive,
                                        Element_Type => Character,
                                        Array_Type   => String,
                                        "<"          => Compare);

   use Ada.Text_Io;
   B : String := "When Roman engineers built a bridge, they had to stand under it while the first legion marched across. If programmers today worked under similar ground rules, they might well find themselves getting much more interested in Ada!";

begin
   Put_Line (B); Sort (B); Put_Line (B);
end Sort_Letters;
Task: Sort the letters of string in alphabetical order








VB: sub bubble(arr)
  n = UBound(arr)
  Do
    nn = -1
    For j = 0 to n - 1
        If arr(j) > arr(j + 1) Then
            temp= arr(j):arr(j)=arr(j+1):arr(j+1)=temp
           nn = j
        End If
    Next
    n = nn
  Loop Until nn = -1
end sub


s="The quick brown fox jumps over the lazy dog, apparently"
redim a(len(s)-1)
for i=1 to len(s)
   a(i-1)=mid(s,i,1)
next
bubble a
s1=join(a,"")
wscript.echo s1




Ada: with Ada.Text_Io;
with Ada.Containers.Generic_Array_Sort;

procedure Sort_Letters is

   function Compare (Left, Right : Character) return Boolean
   is (Left < Right);

   procedure Sort is new
     Ada.Containers.Generic_Array_Sort (Index_Type   => Positive,
                                        Element_Type => Character,
                                        Array_Type   => String,
                                        "<"          => Compare);

   use Ada.Text_Io;
   B : String := "When Roman engineers built a bridge, they had to stand under it while the first legion marched across. If programmers today worked under similar ground rules, they might well find themselves getting much more interested in Ada!";

begin
   Put_Line (B); Sort (B); Put_Line (B);
end Sort_Letters;
Task: Sort the letters of string in alphabetical order

C: #include <stdio.h>


void strsort(char *s) {
    unsigned int n[256] = {0};
    unsigned char i = 0;
    char *t = s;
    while (*s) ++n[(unsigned char) *s++];
    while (++i) while (n[i]--) *t++ = (char) i;
}

int main() {
    char s[] = "Now is the time for all good men "
               "to come to the aid of their country.";
    puts(s);
    strsort(s);
    puts(s);
    return 0;
}
Task: Sort the letters of string in alphabetical order



C#: using System; using static System.Console;
class Program {
  static void Main(string[] args) {
    var nl = "\n";
    var omit_spaces = true;
    var str = "forever ring programming language";
    Write( "working..." + nl );
    Write( "Sort the letters of string in alphabitical order:" + nl );
    Write( "Input: " + str + nl );
    Write( "Output: " );
    for (var ch = omit_spaces ? 33 : 0; ch < 256; ch++)
      foreach (var itm in str)
        if (ch == itm) Console.Write(itm);
    Write( nl + "done..." );
  }
}
Task: Sort the letters of string in alphabetical order


C++: #include <algorithm>
#include <iostream>

int main() {
    std::string s = "Now is the time for all good men "
                    "to come to the aid of our country.";
    
    std::cout << s << std::endl;
    std::sort(s.begin(), s.end());
    std::cout << s << std::endl; 
    return 0;
}
Task: Sort the letters of string in alphabetical order







Python: 

from functools import reduce



def qSort(xs):
    
    if xs:
        h = xs[0]
        below, above = partition(
            lambda v: v <= h
        )(xs[1:])

        return qSort(below) + [h] + qSort(above)
    else:
        return []



def main():
    
    print(quoted('"')(
        ''.join(qSort(list(
            "Is this misspelling of alphabetical as alphabitical a joke ?"
        )))
    ))





def partition(p):
    
    def go(a, x):
        ts, fs = a
        return (ts + [x], fs) if p(x) else (ts, fs + [x])
    return lambda xs: reduce(go, xs, ([], []))



def quoted(c):
    
    return lambda s: c + s + c



if __name__ == '__main__':
    main()
Task: Sort the letters of string in alphabetical order








VB: sub bubble(arr)
  n = UBound(arr)
  Do
    nn = -1
    For j = 0 to n - 1
        If arr(j) > arr(j + 1) Then
            temp= arr(j):arr(j)=arr(j+1):arr(j+1)=temp
           nn = j
        End If
    Next
    n = nn
  Loop Until nn = -1
end sub


s="The quick brown fox jumps over the lazy dog, apparently"
redim a(len(s)-1)
for i=1 to len(s)
   a(i-1)=mid(s,i,1)
next
bubble a
s1=join(a,"")
wscript.echo s1
Task: Sort the letters of string in alphabetical order




Go: package main

import (
    "fmt"
    "strings"
)

func bubbleSort(s string, trim bool) string { 
    chars := []rune(s)
    n := len(chars)
    for {
        n2 := 0
        for i := 1; i < n; i++ {
            if chars[i-1] > chars[i] {
                tmp := chars[i]
                chars[i] = chars[i-1]
                chars[i-1] = tmp
                n2 = i
            }
        }
        n = n2
        if n == 0 {
            break
        }
    }
    s = string(chars)
    if trim {
        s = strings.TrimLeft(s, " \t\r\n")
    }
    return s
}

func main() {
    ss := []string{
        "forever go programming language",
        "Now is the time for all good men to come to the aid of their country.",
    }
    trims := []bool{true, false}
    for i, s := range ss {
        res := bubbleSort(s, trims[i])
        fmt.Printf("Unsorted->%s\n", s)
        fmt.Printf("Sorted  ->%s\n\n", res)
    }
}
Task: Tokenize a string



C#: string str = "Hello,How,Are,You,Today"; 


string[] strings = str.Split(',');
Console.WriteLine(String.Join(".", strings));









Ada: with Ada.Text_IO, Ada.Containers.Indefinite_Vectors, Ada.Strings.Fixed, Ada.Strings.Maps;
use Ada.Text_IO, Ada.Containers, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;

procedure Tokenize is
   package String_Vectors is new Indefinite_Vectors (Positive, String);
   use String_Vectors;
   Input  : String   := "Hello,How,Are,You,Today";
   Start  : Positive := Input'First;
   Finish : Natural  := 0;
   Output : Vector   := Empty_Vector;
begin
   while Start <= Input'Last loop
      Find_Token (Input, To_Set (','), Start, Outside, Start, Finish);
      exit when Start > Finish;
      Output.Append (Input (Start .. Finish));
      Start := Finish + 1;
   end loop;
   for S of Output loop
      Put (S & ".");
   end loop;
end Tokenize;
Task: Tokenize a string

C: #include<string.h>
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	char *a[5];
	const char *s="Hello,How,Are,You,Today";
	int n=0, nn;

	char *ds=strdup(s);

	a[n]=strtok(ds, ",");
	while(a[n] && n<4) a[++n]=strtok(NULL, ",");

	for(nn=0; nn<=n; ++nn) printf("%s.", a[nn]);
	putchar('\n');

	free(ds);

	return 0;
}











Ada: with Ada.Text_IO, Ada.Containers.Indefinite_Vectors, Ada.Strings.Fixed, Ada.Strings.Maps;
use Ada.Text_IO, Ada.Containers, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;

procedure Tokenize is
   package String_Vectors is new Indefinite_Vectors (Positive, String);
   use String_Vectors;
   Input  : String   := "Hello,How,Are,You,Today";
   Start  : Positive := Input'First;
   Finish : Natural  := 0;
   Output : Vector   := Empty_Vector;
begin
   while Start <= Input'Last loop
      Find_Token (Input, To_Set (','), Start, Outside, Start, Finish);
      exit when Start > Finish;
      Output.Append (Input (Start .. Finish));
      Start := Finish + 1;
   end loop;
   for S of Output loop
      Put (S & ".");
   end loop;
end Tokenize;
Task: Tokenize a string


C++: #include <string>
#include <sstream>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
int main()
{
    std::string s = "Hello,How,Are,You,Today";
    std::vector<std::string> v;
    std::istringstream buf(s);
    for(std::string token; getline(buf, token, ','); )
        v.push_back(token);
    copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
    std::cout << '\n';
}










Ada: with Ada.Text_IO, Ada.Containers.Indefinite_Vectors, Ada.Strings.Fixed, Ada.Strings.Maps;
use Ada.Text_IO, Ada.Containers, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;

procedure Tokenize is
   package String_Vectors is new Indefinite_Vectors (Positive, String);
   use String_Vectors;
   Input  : String   := "Hello,How,Are,You,Today";
   Start  : Positive := Input'First;
   Finish : Natural  := 0;
   Output : Vector   := Empty_Vector;
begin
   while Start <= Input'Last loop
      Find_Token (Input, To_Set (','), Start, Outside, Start, Finish);
      exit when Start > Finish;
      Output.Append (Input (Start .. Finish));
      Start := Finish + 1;
   end loop;
   for S of Output loop
      Put (S & ".");
   end loop;
end Tokenize;
Task: Tokenize a string




Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    s := "Hello,How,Are,You,Today"
    fmt.Println(strings.Join(strings.Split(s, ","), "."))
}








Ada: with Ada.Text_IO, Ada.Containers.Indefinite_Vectors, Ada.Strings.Fixed, Ada.Strings.Maps;
use Ada.Text_IO, Ada.Containers, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;

procedure Tokenize is
   package String_Vectors is new Indefinite_Vectors (Positive, String);
   use String_Vectors;
   Input  : String   := "Hello,How,Are,You,Today";
   Start  : Positive := Input'First;
   Finish : Natural  := 0;
   Output : Vector   := Empty_Vector;
begin
   while Start <= Input'Last loop
      Find_Token (Input, To_Set (','), Start, Outside, Start, Finish);
      exit when Start > Finish;
      Output.Append (Input (Start .. Finish));
      Start := Finish + 1;
   end loop;
   for S of Output loop
      Put (S & ".");
   end loop;
end Tokenize;
Task: Tokenize a string





Java: String toTokenize = "Hello,How,Are,You,Today";
System.out.println(String.join(".", toTokenize.split(",")));







Ada: with Ada.Text_IO, Ada.Containers.Indefinite_Vectors, Ada.Strings.Fixed, Ada.Strings.Maps;
use Ada.Text_IO, Ada.Containers, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;

procedure Tokenize is
   package String_Vectors is new Indefinite_Vectors (Positive, String);
   use String_Vectors;
   Input  : String   := "Hello,How,Are,You,Today";
   Start  : Positive := Input'First;
   Finish : Natural  := 0;
   Output : Vector   := Empty_Vector;
begin
   while Start <= Input'Last loop
      Find_Token (Input, To_Set (','), Start, Outside, Start, Finish);
      exit when Start > Finish;
      Output.Append (Input (Start .. Finish));
      Start := Finish + 1;
   end loop;
   for S of Output loop
      Put (S & ".");
   end loop;
end Tokenize;
Task: Tokenize a string







Python: let text = 'Hello,How,Are,You,Today'
let tokens = text.split(||,||)
print tokens.join(with: '.')





Ada: with Ada.Text_IO, Ada.Containers.Indefinite_Vectors, Ada.Strings.Fixed, Ada.Strings.Maps;
use Ada.Text_IO, Ada.Containers, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;

procedure Tokenize is
   package String_Vectors is new Indefinite_Vectors (Positive, String);
   use String_Vectors;
   Input  : String   := "Hello,How,Are,You,Today";
   Start  : Positive := Input'First;
   Finish : Natural  := 0;
   Output : Vector   := Empty_Vector;
begin
   while Start <= Input'Last loop
      Find_Token (Input, To_Set (','), Start, Outside, Start, Finish);
      exit when Start > Finish;
      Output.Append (Input (Start .. Finish));
      Start := Finish + 1;
   end loop;
   for S of Output loop
      Put (S & ".");
   end loop;
end Tokenize;
Task: Tokenize a string








VB: WScript.Echo Join(Split("Hello,How,Are,You,Today", ","), ".")




Ada: with Ada.Text_IO, Ada.Containers.Indefinite_Vectors, Ada.Strings.Fixed, Ada.Strings.Maps;
use Ada.Text_IO, Ada.Containers, Ada.Strings, Ada.Strings.Fixed, Ada.Strings.Maps;

procedure Tokenize is
   package String_Vectors is new Indefinite_Vectors (Positive, String);
   use String_Vectors;
   Input  : String   := "Hello,How,Are,You,Today";
   Start  : Positive := Input'First;
   Finish : Natural  := 0;
   Output : Vector   := Empty_Vector;
begin
   while Start <= Input'Last loop
      Find_Token (Input, To_Set (','), Start, Outside, Start, Finish);
      exit when Start > Finish;
      Output.Append (Input (Start .. Finish));
      Start := Finish + 1;
   end loop;
   for S of Output loop
      Put (S & ".");
   end loop;
end Tokenize;
Task: Tokenize a string

C: #include<string.h>
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	char *a[5];
	const char *s="Hello,How,Are,You,Today";
	int n=0, nn;

	char *ds=strdup(s);

	a[n]=strtok(ds, ",");
	while(a[n] && n<4) a[++n]=strtok(NULL, ",");

	for(nn=0; nn<=n; ++nn) printf("%s.", a[nn]);
	putchar('\n');

	free(ds);

	return 0;
}
Task: Tokenize a string



C#: string str = "Hello,How,Are,You,Today"; 


string[] strings = str.Split(',');
Console.WriteLine(String.Join(".", strings));
Task: Tokenize a string


C++: #include <string>
#include <sstream>
#include <vector>
#include <iterator>
#include <iostream>
#include <algorithm>
int main()
{
    std::string s = "Hello,How,Are,You,Today";
    std::vector<std::string> v;
    std::istringstream buf(s);
    for(std::string token; getline(buf, token, ','); )
        v.push_back(token);
    copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "."));
    std::cout << '\n';
}
Task: Tokenize a string





Java: String toTokenize = "Hello,How,Are,You,Today";
System.out.println(String.join(".", toTokenize.split(",")));
Task: Tokenize a string







Python: let text = 'Hello,How,Are,You,Today'
let tokens = text.split(||,||)
print tokens.join(with: '.')
Task: Tokenize a string








VB: WScript.Echo Join(Split("Hello,How,Are,You,Today", ","), ".")
Task: Tokenize a string




Go: package main

import (
    "fmt"
    "strings"
)

func main() {
    s := "Hello,How,Are,You,Today"
    fmt.Println(strings.Join(strings.Split(s, ","), "."))
}
Task: Tokenize a string



C#: string str = "Hello,How,Are,You,Today"; 


string[] strings = str.Split(',');
Console.WriteLine(String.Join(".", strings));








Fortran: PROGRAM Example

  CHARACTER(23) :: str = "Hello,How,Are,You,Today"
  CHARACTER(5) :: word(5)
  INTEGER :: pos1 = 1, pos2, n = 0, i

  DO
    pos2 = INDEX(str(pos1:), ",")
    IF (pos2 == 0) THEN
       n = n + 1
       word(n) = str(pos1:)
       EXIT
    END IF
    n = n + 1
    word(n) = str(pos1:pos1+pos2-2)
    pos1 = pos2+pos1
 END DO

 DO i = 1, n
   WRITE(*,"(2A)", ADVANCE="NO") TRIM(word(i)), "."
 END DO
 
END PROGRAM Example