WeixiangYan/CodeTransOcean huggingface dataset:
Task: Find the last Sunday of each month


C++: #include <windows.h>
#include <iostream>
#include <string>


using namespace std;


class lastSunday
{
public:
    lastSunday()
    {
	m[0]  = "JANUARY:   "; m[1]  = "FEBRUARY:  "; m[2]  = "MARCH:     "; m[3]  = "APRIL:     "; 
	m[4]  = "MAY:       "; m[5]  = "JUNE:      "; m[6]  = "JULY:      "; m[7]  = "AUGUST:    "; 
	m[8]  = "SEPTEMBER: "; m[9]  = "OCTOBER:   "; m[10] = "NOVEMBER:  "; m[11] = "DECEMBER:  "; 
    }

    void findLastSunday( int y )
    {
	year = y;
	isleapyear();

	int days[] = { 31, isleap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
		d;
	for( int i = 0; i < 12; i++ )
	{
	    d = days[i];
	    while( true )
	    {
		if( !getWeekDay( i, d ) ) break;
		d--;
	    }
	    lastDay[i] = d;
	}

	display();
    }

private:
    void isleapyear()
    {
	isleap = false;
	if( !( year % 4 ) )
	{
	    if( year % 100 ) isleap = true;
	    else if( !( year % 400 ) ) isleap = true;
	}
    }

    void display()
    {
	system( "cls" );
	cout << "  YEAR " << year << endl << "=============" << endl;
	for( int x = 0; x < 12; x++ )
	    cout << m[x] << lastDay[x] << endl;

	cout << endl << endl;
    }

    int getWeekDay( int m, int d )
    {
	int y = year;

	int f = y + d + 3 * m - 1;
	m++;
	if( m < 3 ) y--;
	else f -= int( .4 * m + 2.3 );

	f += int( y / 4 ) - int( ( y / 100 + 1 ) * 0.75 );
	f %= 7;

	return f;
    }

    int lastDay[12], year;
    string m[12];
    bool isleap;
};

int main( int argc, char* argv[] )
{
    int y;
    lastSunday ls;

    while( true )
    {
	system( "cls" );
	cout << "Enter the year( yyyy ) --- ( 0 to quit ): "; 
	cin >> y;
	if( !y ) return 0;

	ls.findLastSunday( y );

	system( "pause" );
    }
    return 0;
}





Java: import java.util.Scanner;

public class LastSunday 
{
	static final String[] months={"January","February","March","April","May","June","July","August","September","October","November","December"};
	
	public static int[] findLastSunday(int year)
	{
		boolean isLeap = isLeapYear(year);
		
		int[] days={31,isLeap?29:28,31,30,31,30,31,31,30,31,30,31};
		int[] lastDay=new int[12];
		
		for(int m=0;i<12;i++)
		{
			int d;
			for(d=days[m]; getWeekDay(year,m,d)!=0; d--)
				;
			lastDay[m]=d;
		}
		
		return lastDay;
	}
	
	private static boolean isLeapYear(int year)
	{
		if(year%4==0)
		{
			if(year%100!=0)
				return true;
			else if (year%400==0)
				return true;
		}
		return false;
	}
	
	private static int getWeekDay(int y, int m, int d)
	{
		int f=y+d+3*m-1;
		m++;
		
		if(m<3)
			y--;
		else
			f-=(int)(0.4*m+2.3);
		
		f+=(int)(y/4)-(int)((y/100+1)*0.75);
		f%=7;
		
		return f;
	}
	
	private static void display(int year, int[] lastDay)
	{
		System.out.println("\nYEAR: "+year);
		for(int m=0;i<12;i++)
			System.out.println(months[m]+": "+lastDay[m]);
	}
	
	public static void main(String[] args) throws Exception
	{
		System.out.print("Enter year: ");
		Scanner s=new Scanner(System.in);
		
		int y=Integer.parseInt(s.next());
		
		int[] lastDay = findLastSunday(y);
		display(y, lastDay);
		
		s.close();
	}
}
Task: Find the last Sunday of each month


C++: #include <windows.h>
#include <iostream>
#include <string>


using namespace std;


class lastSunday
{
public:
    lastSunday()
    {
	m[0]  = "JANUARY:   "; m[1]  = "FEBRUARY:  "; m[2]  = "MARCH:     "; m[3]  = "APRIL:     "; 
	m[4]  = "MAY:       "; m[5]  = "JUNE:      "; m[6]  = "JULY:      "; m[7]  = "AUGUST:    "; 
	m[8]  = "SEPTEMBER: "; m[9]  = "OCTOBER:   "; m[10] = "NOVEMBER:  "; m[11] = "DECEMBER:  "; 
    }

    void findLastSunday( int y )
    {
	year = y;
	isleapyear();

	int days[] = { 31, isleap ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
		d;
	for( int i = 0; i < 12; i++ )
	{
	    d = days[i];
	    while( true )
	    {
		if( !getWeekDay( i, d ) ) break;
		d--;
	    }
	    lastDay[i] = d;
	}

	display();
    }

private:
    void isleapyear()
    {
	isleap = false;
	if( !( year % 4 ) )
	{
	    if( year % 100 ) isleap = true;
	    else if( !( year % 400 ) ) isleap = true;
	}
    }

    void display()
    {
	system( "cls" );
	cout << "  YEAR " << year << endl << "=============" << endl;
	for( int x = 0; x < 12; x++ )
	    cout << m[x] << lastDay[x] << endl;

	cout << endl << endl;
    }

    int getWeekDay( int m, int d )
    {
	int y = year;

	int f = y + d + 3 * m - 1;
	m++;
	if( m < 3 ) y--;
	else f -= int( .4 * m + 2.3 );

	f += int( y / 4 ) - int( ( y / 100 + 1 ) * 0.75 );
	f %= 7;

	return f;
    }

    int lastDay[12], year;
    string m[12];
    bool isleap;
};

int main( int argc, char* argv[] )
{
    int y;
    lastSunday ls;

    while( true )
    {
	system( "cls" );
	cout << "Enter the year( yyyy ) --- ( 0 to quit ): "; 
	cin >> y;
	if( !y ) return 0;

	ls.findLastSunday( y );

	system( "pause" );
    }
    return 0;
}







Python: import sys
import calendar

year = 2013
if len(sys.argv) > 1:
    try:
        year = int(sys.argv[-1])
    except ValueError:
        pass

for month in range(1, 13):
    last_sunday = max(week[-1] for week in calendar.monthcalendar(year, month))
    print('{}-{}-{:2}'.format(year, calendar.month_abbr[month], last_sunday))
Task: Find the last Sunday of each month



C#: using System;

namespace LastSundayOfEachMonth
{
    class Program
    {
        static void Main()
        {
            Console.Write("Year to calculate: ");

            string strYear = Console.ReadLine();
            int year = Convert.ToInt32(strYear);

            DateTime date;
            for (int i = 1; i <= 12; i++)
            {
                date = new DateTime(year, i, DateTime.DaysInMonth(year, i), System.Globalization.CultureInfo.CurrentCulture.Calendar);
                
                
                int daysOffset = date.DayOfWeek - dayOfWeek; 
                if (daysOffset < 0) daysOffset += 7; 
                date = date.AddDays(-daysOffset ); 
                Console.WriteLine(date.ToString("yyyy-MM-dd"));
            }
        }
    }
}


Go: package main

import (
	"fmt"
	"time"
)

func main() {
	
	var year int
	var t time.Time
	var lastDay = [12]int { 31,29,31,30,31,30,31,31,30,31,30,31 }
	
	for {
		fmt.Print("Please select a year: ")
		_, err := fmt.Scanf("%d", &year)
		if err != nil {
			fmt.Println(err)
			continue
		} else {
			break
		}
	}

	fmt.Println("Last Sundays of each month of", year)
	fmt.Println("==================================")

	for i := 1;i < 13; i++ {
		j := lastDay[i-1]
		if i == 2 {
			if time.Date(int(year), time.Month(i), j, 0, 0, 0, 0, time.UTC).Month() == time.Date(int(year), time.Month(i), j-1, 0, 0, 0, 0, time.UTC).Month() {
				j = 29
			} else {
				j = 28
			}
		}
		for {
			t = time.Date(int(year), time.Month(i), j, 0, 0, 0, 0, time.UTC)
			if t.Weekday() == 0 {
				fmt.Printf("%s: %d\n", time.Month(i), j)
				break
			}
			j = j - 1
		}
	}
}
Task: Find the last Sunday of each month



C#: using System;

namespace LastSundayOfEachMonth
{
    class Program
    {
        static void Main()
        {
            Console.Write("Year to calculate: ");

            string strYear = Console.ReadLine();
            int year = Convert.ToInt32(strYear);

            DateTime date;
            for (int i = 1; i <= 12; i++)
            {
                date = new DateTime(year, i, DateTime.DaysInMonth(year, i), System.Globalization.CultureInfo.CurrentCulture.Calendar);
                
                
                int daysOffset = date.DayOfWeek - dayOfWeek; 
                if (daysOffset < 0) daysOffset += 7; 
                date = date.AddDays(-daysOffset ); 
                Console.WriteLine(date.ToString("yyyy-MM-dd"));
            }
        }
    }
}



Java: import java.util.Scanner;

public class LastSunday 
{
	static final String[] months={"January","February","March","April","May","June","July","August","September","October","November","December"};
	
	public static int[] findLastSunday(int year)
	{
		boolean isLeap = isLeapYear(year);
		
		int[] days={31,isLeap?29:28,31,30,31,30,31,31,30,31,30,31};
		int[] lastDay=new int[12];
		
		for(int m=0;i<12;i++)
		{
			int d;
			for(d=days[m]; getWeekDay(year,m,d)!=0; d--)
				;
			lastDay[m]=d;
		}
		
		return lastDay;
	}
	
	private static boolean isLeapYear(int year)
	{
		if(year%4==0)
		{
			if(year%100!=0)
				return true;
			else if (year%400==0)
				return true;
		}
		return false;
	}
	
	private static int getWeekDay(int y, int m, int d)
	{
		int f=y+d+3*m-1;
		m++;
		
		if(m<3)
			y--;
		else
			f-=(int)(0.4*m+2.3);
		
		f+=(int)(y/4)-(int)((y/100+1)*0.75);
		f%=7;
		
		return f;
	}
	
	private static void display(int year, int[] lastDay)
	{
		System.out.println("\nYEAR: "+year);
		for(int m=0;i<12;i++)
			System.out.println(months[m]+": "+lastDay[m]);
	}
	
	public static void main(String[] args) throws Exception
	{
		System.out.print("Enter year: ");
		Scanner s=new Scanner(System.in);
		
		int y=Integer.parseInt(s.next());
		
		int[] lastDay = findLastSunday(y);
		display(y, lastDay);
		
		s.close();
	}
}
Task: Find the last Sunday of each month



C#: using System;

namespace LastSundayOfEachMonth
{
    class Program
    {
        static void Main()
        {
            Console.Write("Year to calculate: ");

            string strYear = Console.ReadLine();
            int year = Convert.ToInt32(strYear);

            DateTime date;
            for (int i = 1; i <= 12; i++)
            {
                date = new DateTime(year, i, DateTime.DaysInMonth(year, i), System.Globalization.CultureInfo.CurrentCulture.Calendar);
                
                
                int daysOffset = date.DayOfWeek - dayOfWeek; 
                if (daysOffset < 0) daysOffset += 7; 
                date = date.AddDays(-daysOffset ); 
                Console.WriteLine(date.ToString("yyyy-MM-dd"));
            }
        }
    }
}





Python: import sys
import calendar

year = 2013
if len(sys.argv) > 1:
    try:
        year = int(sys.argv[-1])
    except ValueError:
        pass

for month in range(1, 13):
    last_sunday = max(week[-1] for week in calendar.monthcalendar(year, month))
    print('{}-{}-{:2}'.format(year, calendar.month_abbr[month], last_sunday))
Task: Find the last Sunday of each month




Go: package main

import (
	"fmt"
	"time"
)

func main() {
	
	var year int
	var t time.Time
	var lastDay = [12]int { 31,29,31,30,31,30,31,31,30,31,30,31 }
	
	for {
		fmt.Print("Please select a year: ")
		_, err := fmt.Scanf("%d", &year)
		if err != nil {
			fmt.Println(err)
			continue
		} else {
			break
		}
	}

	fmt.Println("Last Sundays of each month of", year)
	fmt.Println("==================================")

	for i := 1;i < 13; i++ {
		j := lastDay[i-1]
		if i == 2 {
			if time.Date(int(year), time.Month(i), j, 0, 0, 0, 0, time.UTC).Month() == time.Date(int(year), time.Month(i), j-1, 0, 0, 0, 0, time.UTC).Month() {
				j = 29
			} else {
				j = 28
			}
		}
		for {
			t = time.Date(int(year), time.Month(i), j, 0, 0, 0, 0, time.UTC)
			if t.Weekday() == 0 {
				fmt.Printf("%s: %d\n", time.Month(i), j)
				break
			}
			j = j - 1
		}
	}
}


Java: import java.util.Scanner;

public class LastSunday 
{
	static final String[] months={"January","February","March","April","May","June","July","August","September","October","November","December"};
	
	public static int[] findLastSunday(int year)
	{
		boolean isLeap = isLeapYear(year);
		
		int[] days={31,isLeap?29:28,31,30,31,30,31,31,30,31,30,31};
		int[] lastDay=new int[12];
		
		for(int m=0;i<12;i++)
		{
			int d;
			for(d=days[m]; getWeekDay(year,m,d)!=0; d--)
				;
			lastDay[m]=d;
		}
		
		return lastDay;
	}
	
	private static boolean isLeapYear(int year)
	{
		if(year%4==0)
		{
			if(year%100!=0)
				return true;
			else if (year%400==0)
				return true;
		}
		return false;
	}
	
	private static int getWeekDay(int y, int m, int d)
	{
		int f=y+d+3*m-1;
		m++;
		
		if(m<3)
			y--;
		else
			f-=(int)(0.4*m+2.3);
		
		f+=(int)(y/4)-(int)((y/100+1)*0.75);
		f%=7;
		
		return f;
	}
	
	private static void display(int year, int[] lastDay)
	{
		System.out.println("\nYEAR: "+year);
		for(int m=0;i<12;i++)
			System.out.println(months[m]+": "+lastDay[m]);
	}
	
	public static void main(String[] args) throws Exception
	{
		System.out.print("Enter year: ");
		Scanner s=new Scanner(System.in);
		
		int y=Integer.parseInt(s.next());
		
		int[] lastDay = findLastSunday(y);
		display(y, lastDay);
		
		s.close();
	}
}
Task: Find the last Sunday of each month





Java: import java.util.Scanner;

public class LastSunday 
{
	static final String[] months={"January","February","March","April","May","June","July","August","September","October","November","December"};
	
	public static int[] findLastSunday(int year)
	{
		boolean isLeap = isLeapYear(year);
		
		int[] days={31,isLeap?29:28,31,30,31,30,31,31,30,31,30,31};
		int[] lastDay=new int[12];
		
		for(int m=0;i<12;i++)
		{
			int d;
			for(d=days[m]; getWeekDay(year,m,d)!=0; d--)
				;
			lastDay[m]=d;
		}
		
		return lastDay;
	}
	
	private static boolean isLeapYear(int year)
	{
		if(year%4==0)
		{
			if(year%100!=0)
				return true;
			else if (year%400==0)
				return true;
		}
		return false;
	}
	
	private static int getWeekDay(int y, int m, int d)
	{
		int f=y+d+3*m-1;
		m++;
		
		if(m<3)
			y--;
		else
			f-=(int)(0.4*m+2.3);
		
		f+=(int)(y/4)-(int)((y/100+1)*0.75);
		f%=7;
		
		return f;
	}
	
	private static void display(int year, int[] lastDay)
	{
		System.out.println("\nYEAR: "+year);
		for(int m=0;i<12;i++)
			System.out.println(months[m]+": "+lastDay[m]);
	}
	
	public static void main(String[] args) throws Exception
	{
		System.out.print("Enter year: ");
		Scanner s=new Scanner(System.in);
		
		int y=Integer.parseInt(s.next());
		
		int[] lastDay = findLastSunday(y);
		display(y, lastDay);
		
		s.close();
	}
}



Python: import sys
import calendar

year = 2013
if len(sys.argv) > 1:
    try:
        year = int(sys.argv[-1])
    except ValueError:
        pass

for month in range(1, 13):
    last_sunday = max(week[-1] for week in calendar.monthcalendar(year, month))
    print('{}-{}-{:2}'.format(year, calendar.month_abbr[month], last_sunday))
Task: Find the last Sunday of each month




Go: package main

import (
	"fmt"
	"time"
)

func main() {
	
	var year int
	var t time.Time
	var lastDay = [12]int { 31,29,31,30,31,30,31,31,30,31,30,31 }
	
	for {
		fmt.Print("Please select a year: ")
		_, err := fmt.Scanf("%d", &year)
		if err != nil {
			fmt.Println(err)
			continue
		} else {
			break
		}
	}

	fmt.Println("Last Sundays of each month of", year)
	fmt.Println("==================================")

	for i := 1;i < 13; i++ {
		j := lastDay[i-1]
		if i == 2 {
			if time.Date(int(year), time.Month(i), j, 0, 0, 0, 0, time.UTC).Month() == time.Date(int(year), time.Month(i), j-1, 0, 0, 0, 0, time.UTC).Month() {
				j = 29
			} else {
				j = 28
			}
		}
		for {
			t = time.Date(int(year), time.Month(i), j, 0, 0, 0, 0, time.UTC)
			if t.Weekday() == 0 {
				fmt.Printf("%s: %d\n", time.Month(i), j)
				break
			}
			j = j - 1
		}
	}
}




Python: import sys
import calendar

year = 2013
if len(sys.argv) > 1:
    try:
        year = int(sys.argv[-1])
    except ValueError:
        pass

for month in range(1, 13):
    last_sunday = max(week[-1] for week in calendar.monthcalendar(year, month))
    print('{}-{}-{:2}'.format(year, calendar.month_abbr[month], last_sunday))
Task: Find words with alternating vowels and consonants

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

#define MAX_WORD_SIZE 80

bool is_vowel(char ch) {
    switch (ch) {
    case 'a': case 'A':
    case 'e': case 'E':
    case 'i': case 'I':
    case 'o': case 'O':
    case 'u': case 'U':
        return true;
    }
    return false;
}

bool alternating_vowels_and_consonants(const char* str, size_t len) {
    for (size_t i = 1; i < len; ++i) {
        if (is_vowel(str[i]) == is_vowel(str[i - 1]))
            return false;
    }
    return true;
}

int main(int argc, char** argv) {
    const char* filename = argc < 2 ? "unixdict.txt" : argv[1];
    FILE* fp = fopen(filename, "r");
    if (!fp) {
        perror(filename);
        return EXIT_FAILURE;
    }
    char line[MAX_WORD_SIZE];
    int n = 1;
    while (fgets(line, sizeof(line), fp)) {
        size_t len = strlen(line) - 1; 
        if (len > 9 && alternating_vowels_and_consonants(line, len))
            printf("%2d: %s", n++, line);
    }
    fclose(fp);
    return EXIT_SUCCESS;
}



C#: #include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>

bool is_vowel(char ch) {
    switch (ch) {
    case 'a': case 'A':
    case 'e': case 'E':
    case 'i': case 'I':
    case 'o': case 'O':
    case 'u': case 'U':
        return true;
    }
    return false;
}

bool alternating_vowels_and_consonants(const std::string& str) {
    for (size_t i = 1, len = str.size(); i < len; ++i) {
        if (is_vowel(str[i]) == is_vowel(str[i - 1]))
            return false;
    }
    return true;
}

int main(int argc, char** argv) {
    const char* filename = argc < 2 ? "unixdict.txt" : argv[1];
    std::ifstream in(filename);
    if (!in) {
        std::cerr << "Cannot open file '" << filename << "'.\n";
        return EXIT_FAILURE;
    }
    std::string line;
    for (int n = 1; getline(in, line); ) {
        if (line.size() > 9 && alternating_vowels_and_consonants(line))
            std::cout << std::setw(2) << n++ << ": " << line << '\n';
    }
    return EXIT_SUCCESS;
}
Task: Find words with alternating vowels and consonants

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

#define MAX_WORD_SIZE 80

bool is_vowel(char ch) {
    switch (ch) {
    case 'a': case 'A':
    case 'e': case 'E':
    case 'i': case 'I':
    case 'o': case 'O':
    case 'u': case 'U':
        return true;
    }
    return false;
}

bool alternating_vowels_and_consonants(const char* str, size_t len) {
    for (size_t i = 1; i < len; ++i) {
        if (is_vowel(str[i]) == is_vowel(str[i - 1]))
            return false;
    }
    return true;
}

int main(int argc, char** argv) {
    const char* filename = argc < 2 ? "unixdict.txt" : argv[1];
    FILE* fp = fopen(filename, "r");
    if (!fp) {
        perror(filename);
        return EXIT_FAILURE;
    }
    char line[MAX_WORD_SIZE];
    int n = 1;
    while (fgets(line, sizeof(line), fp)) {
        size_t len = strlen(line) - 1; 
        if (len > 9 && alternating_vowels_and_consonants(line, len))
            printf("%2d: %s", n++, line);
    }
    fclose(fp);
    return EXIT_SUCCESS;
}







Python: 



def isLongAlternator(s):
    
    def p(a, b):
        return isVowel(a) != isVowel(b)
    return 9 < len(s) and all(map(p, s, s[1:]))


def isVowel(c):
    
    return c in 'aeiou'




def main():
    
    matches = [
        x for x in readFile('unixdict.txt').splitlines()
        if isLongAlternator(x)
    ]
    w = max(len(x) for x in matches)
    print(str(len(matches)) + ' matching words:\n')
    print(
        '\n'.join(
            ' '.join(s) for s in chunksOf(4)([
                x.ljust(w, ' ') for x in matches
            ])
        )
    )





def chunksOf(n):
    
    def go(xs):
        return (
            xs[i:n + i] for i in range(0, len(xs), n)
        ) if 0 < n else None
    return go



def readFile(fp):
    
    with open(fp, 'r', encoding='utf-8') as f:
        return f.read()



if __name__ == '__main__':
    main()
Task: Find words with alternating vowels and consonants




Go: package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "log"
    "strings"
    "unicode/utf8"
)

func isVowel(c rune) bool { return strings.ContainsRune("aeiou", c) }

func main() {
    wordList := "unixdict.txt"
    b, err := ioutil.ReadFile(wordList)
    if err != nil {
        log.Fatal("Error reading file")
    }
    bwords := bytes.Fields(b)
    var words []string
    for _, bword := range bwords {
        s := string(bword)
        if utf8.RuneCountInString(s) > 9 {
            words = append(words, s)
        }
    }
    count := 0
    fmt.Println("Words with alternate consonants and vowels in", wordList, "\b:\n")
    for _, word := range words {
        found := true
        for i, c := range word {
            if (i%2 == 0 && isVowel(c)) || (i%2 == 1 && !isVowel(c)) {
                found = false
                break
            }
        }
        if !found {
            found = true
            for i, c := range word {
                if (i%2 == 0 && !isVowel(c)) || (i%2 == 1 && isVowel(c)) {
                    found = false
                    break
                }
            }
        }
        if found {
            count++
            fmt.Printf("%2d: %s\n", count, word)
        }
    }
}




Python: 



def isLongAlternator(s):
    
    def p(a, b):
        return isVowel(a) != isVowel(b)
    return 9 < len(s) and all(map(p, s, s[1:]))


def isVowel(c):
    
    return c in 'aeiou'




def main():
    
    matches = [
        x for x in readFile('unixdict.txt').splitlines()
        if isLongAlternator(x)
    ]
    w = max(len(x) for x in matches)
    print(str(len(matches)) + ' matching words:\n')
    print(
        '\n'.join(
            ' '.join(s) for s in chunksOf(4)([
                x.ljust(w, ' ') for x in matches
            ])
        )
    )





def chunksOf(n):
    
    def go(xs):
        return (
            xs[i:n + i] for i in range(0, len(xs), n)
        ) if 0 < n else None
    return go



def readFile(fp):
    
    with open(fp, 'r', encoding='utf-8') as f:
        return f.read()



if __name__ == '__main__':
    main()
Task: Find words with alternating vowels and consonants

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

#define MAX_WORD_SIZE 80

bool is_vowel(char ch) {
    switch (ch) {
    case 'a': case 'A':
    case 'e': case 'E':
    case 'i': case 'I':
    case 'o': case 'O':
    case 'u': case 'U':
        return true;
    }
    return false;
}

bool alternating_vowels_and_consonants(const char* str, size_t len) {
    for (size_t i = 1; i < len; ++i) {
        if (is_vowel(str[i]) == is_vowel(str[i - 1]))
            return false;
    }
    return true;
}

int main(int argc, char** argv) {
    const char* filename = argc < 2 ? "unixdict.txt" : argv[1];
    FILE* fp = fopen(filename, "r");
    if (!fp) {
        perror(filename);
        return EXIT_FAILURE;
    }
    char line[MAX_WORD_SIZE];
    int n = 1;
    while (fgets(line, sizeof(line), fp)) {
        size_t len = strlen(line) - 1; 
        if (len > 9 && alternating_vowels_and_consonants(line, len))
            printf("%2d: %s", n++, line);
    }
    fclose(fp);
    return EXIT_SUCCESS;
}


C++: #include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>

bool is_vowel(char ch) {
    switch (ch) {
    case 'a': case 'A':
    case 'e': case 'E':
    case 'i': case 'I':
    case 'o': case 'O':
    case 'u': case 'U':
        return true;
    }
    return false;
}

bool alternating_vowels_and_consonants(const std::string& str) {
    for (size_t i = 1, len = str.size(); i < len; ++i) {
        if (is_vowel(str[i]) == is_vowel(str[i - 1]))
            return false;
    }
    return true;
}

int main(int argc, char** argv) {
    const char* filename = argc < 2 ? "unixdict.txt" : argv[1];
    std::ifstream in(filename);
    if (!in) {
        std::cerr << "Cannot open file '" << filename << "'.\n";
        return EXIT_FAILURE;
    }
    std::string line;
    for (int n = 1; getline(in, line); ) {
        if (line.size() > 9 && alternating_vowels_and_consonants(line))
            std::cout << std::setw(2) << n++ << ": " << line << '\n';
    }
    return EXIT_SUCCESS;
}