WeixiangYan/CodeTransOcean huggingface dataset:
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';
}









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
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;
}










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
Task: Tokenize a string





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






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
Task: Tokenize a string







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




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
Task: Tokenize a string








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



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
Task: Tokenize a string






PHP: <?php
$str = 'Hello,How,Are,You,Today';
echo implode('.', explode(',', $str));
?>





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
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;
}









COBOL:       identification division.
       program-id. tokenize.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 period constant as ".".
       01 cmma   constant as ",".

       01 start-with.
          05 value "Hello,How,Are,You,Today".

       01 items.
          05 item pic x(6) occurs 5 times.

       procedure division.
       tokenize-main.
       unstring start-with delimited by cmma
           into item(1) item(2) item(3) item(4) item(5)

       display trim(item(1)) period trim(item(2)) period
               trim(item(3)) period trim(item(4)) period
               trim(item(5))

       goback.
       end program tokenize.
Task: Tokenize a string



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


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







COBOL:       identification division.
       program-id. tokenize.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 period constant as ".".
       01 cmma   constant as ",".

       01 start-with.
          05 value "Hello,How,Are,You,Today".

       01 items.
          05 item pic x(6) occurs 5 times.

       procedure division.
       tokenize-main.
       unstring start-with delimited by cmma
           into item(1) item(2) item(3) item(4) item(5)

       display trim(item(1)) period trim(item(2)) period
               trim(item(3)) period trim(item(4)) period
               trim(item(5))

       goback.
       end program 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';
}








COBOL:       identification division.
       program-id. tokenize.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 period constant as ".".
       01 cmma   constant as ",".

       01 start-with.
          05 value "Hello,How,Are,You,Today".

       01 items.
          05 item pic x(6) occurs 5 times.

       procedure division.
       tokenize-main.
       unstring start-with delimited by cmma
           into item(1) item(2) item(3) item(4) item(5)

       display trim(item(1)) period trim(item(2)) period
               trim(item(3)) period trim(item(4)) period
               trim(item(5))

       goback.
       end program tokenize.
Task: Tokenize a string





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





COBOL:       identification division.
       program-id. tokenize.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 period constant as ".".
       01 cmma   constant as ",".

       01 start-with.
          05 value "Hello,How,Are,You,Today".

       01 items.
          05 item pic x(6) occurs 5 times.

       procedure division.
       tokenize-main.
       unstring start-with delimited by cmma
           into item(1) item(2) item(3) item(4) item(5)

       display trim(item(1)) period trim(item(2)) period
               trim(item(3)) period trim(item(4)) period
               trim(item(5))

       goback.
       end program tokenize.
Task: Tokenize a string







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



COBOL:       identification division.
       program-id. tokenize.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 period constant as ".".
       01 cmma   constant as ",".

       01 start-with.
          05 value "Hello,How,Are,You,Today".

       01 items.
          05 item pic x(6) occurs 5 times.

       procedure division.
       tokenize-main.
       unstring start-with delimited by cmma
           into item(1) item(2) item(3) item(4) item(5)

       display trim(item(1)) period trim(item(2)) period
               trim(item(3)) period trim(item(4)) period
               trim(item(5))

       goback.
       end program tokenize.
Task: Tokenize a string








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


COBOL:       identification division.
       program-id. tokenize.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 period constant as ".".
       01 cmma   constant as ",".

       01 start-with.
          05 value "Hello,How,Are,You,Today".

       01 items.
          05 item pic x(6) occurs 5 times.

       procedure division.
       tokenize-main.
       unstring start-with delimited by cmma
           into item(1) item(2) item(3) item(4) item(5)

       display trim(item(1)) period trim(item(2)) period
               trim(item(3)) period trim(item(4)) period
               trim(item(5))

       goback.
       end program 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, ","), "."))
}






COBOL:       identification division.
       program-id. tokenize.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 period constant as ".".
       01 cmma   constant as ",".

       01 start-with.
          05 value "Hello,How,Are,You,Today".

       01 items.
          05 item pic x(6) occurs 5 times.

       procedure division.
       tokenize-main.
       unstring start-with delimited by cmma
           into item(1) item(2) item(3) item(4) item(5)

       display trim(item(1)) period trim(item(2)) period
               trim(item(3)) period trim(item(4)) period
               trim(item(5))

       goback.
       end program tokenize.
Task: Tokenize a string






PHP: <?php
$str = 'Hello,How,Are,You,Today';
echo implode('.', explode(',', $str));
?>
Task: Tokenize a string






PHP: <?php
$str = 'Hello,How,Are,You,Today';
echo implode('.', explode(',', $str));
?>






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






PHP: <?php
$str = 'Hello,How,Are,You,Today';
echo implode('.', explode(',', $str));
?>




COBOL:       identification division.
       program-id. tokenize.

       environment division.
       configuration section.
       repository.
           function all intrinsic.

       data division.
       working-storage section.
       01 period constant as ".".
       01 cmma   constant as ",".

       01 start-with.
          05 value "Hello,How,Are,You,Today".

       01 items.
          05 item pic x(6) occurs 5 times.

       procedure division.
       tokenize-main.
       unstring start-with delimited by cmma
           into item(1) item(2) item(3) item(4) item(5)

       display trim(item(1)) period trim(item(2)) period
               trim(item(3)) period trim(item(4)) period
               trim(item(5))

       goback.
       end program tokenize.
Task: Holidays related to Easter



C#: using System;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;

internal class Program
{
    private static readonly OrderedDictionary _holidayOffsets = new OrderedDictionary
                                                                    {
                                                                        {"Easter", 0},
                                                                        {"Ascension", 39},
                                                                        {"Pentecost", 49},
                                                                        {"Trinity", 56},
                                                                        {"Corpus", 60},
                                                                    };

    static void Main(string[] args)
    {
        Console.WriteLine("Christian holidays, related to Easter, for each centennial from 400 to 2100 CE:");
        for (int year = 400; year <= 2100; year += 100)
            OutputHolidays(year);

        Console.WriteLine();
        Console.WriteLine("Christian holidays, related to Easter, for years from 2010 to 2020 CE:");
        for (int year = 2010; year <= 2020; year += 1)
            OutputHolidays(year);
    }

    static void OutputHolidays(int year)
    {
        var easter = CalculateEaster(year);
        var holidays = from kp in _holidayOffsets.OfType<DictionaryEntry>()
                       let holiday = easter.AddDays(Convert.ToInt32(kp.Value))
                       select kp.Key + ": " + string.Format("{0,2:ddd} {0,2:%d} {0:MMM}", holiday);
        Console.WriteLine("{0,4} {1}", year, string.Join(", ", holidays.ToArray()));
    }

    static DateTime CalculateEaster(int year)
    {
        var a = year % 19;
        var b = year / 100;
        var c = year %100;
        var d = b / 4;
        var e = b % 4;
        var f = (b + 8) / 25;
        var g = (b - f + 1) / 3;
        var h = (19 * a + b - d - g + 15) % 30;
        var i = c / 4;
        var k = c % 4;
        var l = (32 + 2 * e + 2 * i - h - k) % 7;
        var m = (a + 11 * h + 22 * l) / 451;
        var numerator = h + l - 7 * m + 114;
        var month = numerator / 31;
        var day = (numerator % 31) + 1;
        return new DateTime(year, month, day);
    }
}
Task: Holidays related to Easter





Java: import java.text.DateFormatSymbols;
import java.util.*;

public class EasterRelatedHolidays {

    final static Map<String, Integer> holidayOffsets;

    static {
        holidayOffsets = new LinkedHashMap<>();
        holidayOffsets.put("Easter", 0);
        holidayOffsets.put("Ascension", 39);
        holidayOffsets.put("Pentecost", 10);
        holidayOffsets.put("Trinity", 7);
        holidayOffsets.put("Corpus", 4);
    }

    public static void main(String[] args) {
        System.out.println("Christian holidays, related to Easter,"
                + " for each centennial from 400 to 2100 CE:");

        for (int y = 400; y <= 2100; y += 100)
            printEasterRelatedHolidays(y);

        System.out.println("\nChristian holidays, related to Easter,"
                + " for years from 2010 to 2020 CE:");
        for (int y = 2010; y < 2021; y++)
            printEasterRelatedHolidays(y);
    }

    static void printEasterRelatedHolidays(int year) {
        final int a = year % 19;
        final int b = year / 100;
        final int c = year % 100;
        final int d = b / 4;
        final int e = b % 4;
        final int f = (b + 8) / 25;
        final int g = (b - f + 1) / 3;
        final int h = (19 * a + b - d - g + 15) % 30;
        final int i = c / 4;
        final int k = c % 4;
        final int l = (32 + 2 * e + 2 * i - h - k) % 7;
        final int m = (a + 11 * h + 22 * l) / 451;
        final int n = h + l - 7 * m + 114;
        final int month = n / 31 - 1;
        final int day = (n % 31) + 1;

        Calendar date = new GregorianCalendar(year, month, day);
        String[] months = new DateFormatSymbols(Locale.US).getShortMonths();

        System.out.printf("%4d ", year);
        for (String hd : holidayOffsets.keySet()) {
            date.add(Calendar.DATE, holidayOffsets.get(hd));
            System.out.printf("%s: %2d %s  ", hd,
                    date.get(Calendar.DAY_OF_MONTH),
                    months[date.get(Calendar.MONTH)]);
        }
        System.out.println();
    }
}
Task: Holidays related to Easter







Python: from dateutil.easter import *
import datetime, calendar

class Holiday(object):
    def __init__(self, date, offset=0):
        self.holiday = date + datetime.timedelta(days=offset)

    def __str__(self):
        dayofweek = calendar.day_name[self.holiday.weekday()][0:3]
        month = calendar.month_name[self.holiday.month][0:3]
        return '{0} {1:2d} {2}'.format(dayofweek, self.holiday.day, month)

def get_holiday_values(year):
    holidays = {'year': year}
    easterDate = easter(year)
    holidays['easter'] = Holiday(easterDate) 
    holidays['ascension'] = Holiday(easterDate, 39)
    holidays['pentecost'] = Holiday(easterDate, 49)
    holidays['trinity'] = Holiday(easterDate, 56)
    holidays['corpus'] = Holiday(easterDate, 60)
    return holidays
    
def print_holidays(holidays):
    print '{year:4d} Easter: {easter}, Ascension: {ascension}, Pentecost: {pentecost}, Trinity: {trinity}, Corpus: {corpus}'.format(**holidays)
    
if __name__ == "__main__":
    print "Christian holidays, related to Easter, for each centennial from 400 to 2100 CE:"
    for year in range(400, 2200, 100):
        print_holidays(get_holiday_values(year))

    print ''
    print "Christian holidays, related to Easter, for years from 2010 to 2020 CE:"
    for year in range(2010, 2021):
        print_holidays(get_holiday_values(year))
Task: Holidays related to Easter








VB: #include "datetime.bi"
#include "string.bi"

Dim Shared As Integer anno, mes, dia

Type mytype
    f As String*9
    d As Short
End Type
Dim Shared fechas(1 To 5) As mytype => {("Easter   ",0),_
("Ascension",39),("Pentecost",49),("Trinity  ",56),("Corpus   ",60)}

Function Pascua(anno As Short) As Double
    Dim As Short a, b, c, d, e
    Dim As Short f, g, h, i, k
    Dim As Short l, m, n
    a = anno Mod 19
    b = anno \ 100
    c = anno Mod 100
    d = b \ 4
    e = b Mod 4
    f = (b + 8) \ 25
    g = (b - f + 1) \ 3
    h = (19 * a + b - d - g + 15) Mod 30
    i = c \ 4
    k = c Mod 4
    l = (32 + 2 * e + 2 * i - h - k) Mod 7
    m = (a + 11 * h + 22 * l) \ 451
    n = h + l - 7 * m + 114
    Dim As Short mes = n \ 31
    Dim As Short dia = n Mod 31 + 1
    Return Dateserial(anno, mes, dia)
End Function

Sub Mostar(anno As Short)
    Dim As Double e = Pascua(anno)
    Print Using (" ####  "); anno; 
    For i As Short = 1 To Ubound(fechas)
        Print Format(e + fechas(i).d, "dd/mmm"); Spc(3);
    Next i
    Print
End Sub

Print " Year  Easter  Ascension  Pentecost  Trinity  C/Christi"
Print "  CE   Sunday  Thursday    Sunday    Sunday   Thursday "
Print " ----  ------  --------- ----------  -------  ---------"

For anno = 400 To 2100 Step 100
    Mostar(anno)
Next anno    
Print
For anno = 2010 To 2020
    Mostar(anno)
Next anno

Sleep
Task: Holidays related to Easter




Go: package main

import (
    "fmt"
    "time"
)

type holiday struct {
    time.Time
}

func easter(y int) holiday {
    c := y / 100
    n := mod(y, 19)
    i := mod(c-c/4-(c-(c-17)/25)/3+19*n+15, 30)
    i -= (i / 28) * (1 - (i/28)*(29/(i+1))*((21-n)/11))
    l := i - mod(y+y/4+i+2-c+c/4, 7)
    m := 3 + (l+40)/44
    d := l + 28 - 31*(m/4)
    return holiday{time.Date(y, time.Month(m), d, 0, 0, 0, 0, time.UTC)}
}

func mod(a, n int) int {
    r := a % n
    if r < 0 {
        return r + n
    }
    return r
}

func (h holiday) addDays(d int) holiday {
    return holiday{h.Add(time.Duration(d) * 24 * time.Hour)}
}

type easterRelated struct {
    easter, ascension, pentecost, trinity, corpusChristi holiday
}

func newEasterRelated(y int) (er easterRelated) {
    er.easter = easter(y)
    er.ascension = er.easter.addDays(39)
    er.pentecost = er.ascension.addDays(10)
    er.trinity = er.pentecost.addDays(7)
    er.corpusChristi = er.trinity.addDays(4)
    return
}

func (er easterRelated) print() {
    const wdmdm = ": Mon _2 Jan"
    fmt.Printf("%4d %s, %s, %s, %s, %s\n",
        er.easter.Year(),
        er.easter.Format("Easter"+wdmdm),
        er.ascension.Format("Ascension"+wdmdm),
        er.pentecost.Format("Pentecost"+wdmdm),
        er.trinity.Format("Trinity"+wdmdm),
        er.corpusChristi.Format("Corpus"+wdmdm))
}

func main() {
    fmt.Println("Christian holidays, related to Easter, " +
        "for each centennial from 400 to 2100 CE:")
    for y := 400; y <= 2100; y += 100 {
        newEasterRelated(y).print()
    }
    fmt.Println("\nChristian holidays, related to Easter, " +
        "for years from 2010 to 2020 CE:")
    for y := 2010; y <= 2020; y++ {
        newEasterRelated(y).print()
    }
}