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; }
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); }
#include <ctime>
using namespace std;
int main() {
int n,m;
FILE *fpt;
cout<<"n = "; cin>>n;
fpt=fopen("input.dat","wb");
srand(time(NULL));
// запись файла
for (int i=0; i<n; i++) {
m=rand()%8000-3000;
cout<<m<<" ";
fwrite(&m,sizeof(int),1,fpt);
}
cout<<endl;
fclose(fpt);
fpt=fopen("input.dat","rb+");
int indf=0,indl=0,vf=0,vl=0,k=0;
// чтение файла
while (fread(&m,sizeof(int),1,fpt)!=0) {
k++;
if (!(m%2==0) && (indf==0)) { indf=k-1; vf=m; }
if ((!m==0) && (m%2==0)) { indl=k-1; vl=m; }
}
cout<<"first odd = "<<vf<<" index = "<<indf<<endl;
cout<<"last even = "<<vl<<" index = "<<indl<<endl;
// обмен первого нечетного и последнего четного
if (indf>0) {
fseek(fpt,sizeof(int)*indf,SEEK_SET);
fwrite(&vl,sizeof(int),1,fpt);
}
if (indl>0) {
fseek(fpt,sizeof(int)*indl,SEEK_SET);
fwrite(&vf,sizeof(int),1,fpt);
}
fclose(fpt);
system("pause");
return 0;
}
n = 6
4368 2733 1112 2620 1941 753
first odd = 2733 index = 1
last even = 2620 index = 3
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;
}
}