Перевести код с pascal на c# program glas; uses crt; type t_str=array[1..10] of string[80]; t_set=set of char; var s,new: t_str; alf,gls,sogl: t_set; kol,i,j,kolg,kolsg,schet: byte; prom: string; begin clrscr; textcolor(green); schet: =1; kolg: =0; kolsg: =0; alf: =['a'..'z']; gls: =['a','e','i','o','u','y']; sogl: =['b','c','d','f','g','h','j','k', 'l','m','n','p','q','r','s','t','v','w','x']; writeln; writeln(' vvedite kol-vo slov(ne > 10 ! ): '); readln(kol); writeln; textcolor(red); writeln(' vvodim tolko zaglavnimi ! '); textcolor(green); writeln; for i: =1 to kol do begin writeln(' vvod ',i,'-go slova: '); readln(s[i]); prom: =s[i]; kolg: =0; kolsg: =0; for j: =1 to length(prom) do begin if (prom[j] in gls) then kolg: =kolg+1 else kolsg: =kolsg+1; end; if kolg> kolsg then begin new[schet]: =prom; schet: =schet+1; end; end; clrscr; writeln; writeln(' ishodnii massiv slov: '); writeln; for i: =1 to kol do begin write(' ',s[i]); end; readkey; writeln; writeln; writeln(' slova gde > glas.'); writeln; for i: =1 to schet do begin write(' ',new[i]); end; readkey; end.
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
internal static class Program
{
private const string glasnye_ = "aeiouy";
private const string soglasnye_ = "bcdfghjklmnpqrstvwxz";
private static void Main()
{
try
{
Console.WriteLine("Введите строку слов (любые символы будут считаться разделителями)");
var s = Console.ReadLine();
Console.WriteLine($"Гласных больше чем согласных:\n {Task1(s).Aggregate("", (current, t) => current + t.ToUpper() + " ")}");
Console.WriteLine();
Console.WriteLine($"Гласных больше чем согласных:\n {Task1Regex(s).Aggregate("", (current, t) => current + t.ToUpper() + " ")}");
Console.ReadLine();
}
catch(Exception e)
{
Console.WriteLine(e);
Console.ReadLine();
}
}
private static IEnumerable<string> Task1(string s)
{
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("Без регулярных выражений");
var words = s.Split(new[] {' ', '-', ',', '.', '*', ':', ';', '_'}, StringSplitOptions.RemoveEmptyEntries).ToList();
var sb = new StringBuilder();
for (var i = 0; i < words.Count; i++)
sb.AppendLine($"Слово[{i}] = {words[i].ToUpper()}");
Console.Write(sb.ToString());
var result = new List<string>();
foreach (var word in words)
{
var k = 0;
foreach (var c in word.ToLower().ToCharArray())
{
k += glasnye_.Contains(c) ? 1 : 0;
k -= soglasnye_.Contains(c) ? 1 : 0;
}
if (k > 0)
result.Add(word);
}
return result;
}
private static IEnumerable<string> Task1Regex(string s)
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("С регулярными выражениями");
var ms = Regex.Matches(s, @"[A-z]+", RegexOptions.IgnoreCase);
var sb = new StringBuilder();
for (var i = 0; i < ms.Count; i++)
sb.AppendLine($"Слово[{i}] = {ms[i].Value.ToUpper()}");
Console.Write(sb.ToString());
var result = new List<string>();
for (var i = 0; i < ms.Count; i++)
{
var v = ms[i].Value;
var k = Regex.Matches(v, $"[{glasnye_}]", RegexOptions.IgnoreCase).Count;
k -= Regex.Matches(v, $"[{soglasnye_}]", RegexOptions.IgnoreCase).Count;
if (k > 0)
result.Add(v);
}
return result;
}
}