20-Mavzu: Berilganlar oqimlariga doir masala yechish. 21-Mavzu: Fayl tizimi va oqimlarga doir masala yechish. 22-Mavzu: Matn va binar fayllar bilan ishlash.
using System;
using System.IO;
using System.Text;
using System.Collections;
namespace Fayl
{
class Program
{
static void Main(string[] args)
{
ArrayList q = new ArrayList();
ArrayList p = new ArrayList();
string path = @"D:\file\file01.txt";
using (StreamReader tr = File.OpenText(path))
{
string s1 = "";
while ((s1 = tr.ReadLine()) != null)
{
q.Add(s1);
}
}
p.AddRange(q);
p.Sort();
int e = q.Count;
int e01 = 0;
int e02 = 0;
string[] a = new string[e];
string[] a1 = new string[e];
foreach (string k in q)
{
a[e01] = k;
e01++;
}
foreach (string k in p)
{
a1[e02] = k;
e02++;
}
int j = 0;
for (int i = 0; i < a.Length; i++)
{
if (a[i] == a1[i])
{
j++;
}
}
if (j == e)
{
Console.WriteLine(true);
}
else
{
Console.WriteLine(false);
}
}
}
}
using System;
using System.IO;
using System.Text;
using System.Collections;
namespace Fayl
{
class Program
{
static void Main(string[] args)
{
ArrayList q = new ArrayList();
string path = @"D:\file\file04.txt";
//File.Create(path);
int n;
Console.Write("n=");
n = Convert.ToInt32(Console.ReadLine());
int r = 97;
int s = 0;
char[] s1 = new char[n];
string[] s2 = new string[n];
for (int j = 0; j < n; j++)
{
s1[j]= (char)(r+s);
s++;
}
for (int i = s2.Length-1; i >=0; i--)
{
for (int j = 0; j < n-i; j++)
{
s2[i]+= s1[j];
}
}
int f = 0;
string[] s3 = new string[n];
for (int i = s2.Length - 1; i >= 0; i--)
{
s3[f] = s2[i];
f++;
}
q.AddRange(s3);
using (StreamWriter ff = File.AppendText(path))
{
foreach (var k in q)
{
ff.WriteLine(k);
}
ff.Close();
Console.WriteLine(File.ReadAllText(path));
}
}
}
}
using System;
using System.IO;
using System.Text;
using System.Collections;
namespace Fayl
{
class Program
{
static void Main(string[] args)
{
ArrayList q = new ArrayList();
ArrayList p = new ArrayList();
string path = @"D:\file\Lorem.txt";
string path1 = @"D:\file\Lorem1.txt";
using (StreamReader tr = File.OpenText(path))
{
string s1 = "";
while ((s1 = tr.ReadLine()) != null)
{
q.Add(s1);
}
}
int n;
Console.Write("k=");
n = Convert.ToInt32(Console.ReadLine());
foreach(string k in q)
{
string s = k;
string[] a = s.Split(' ');
for (int i = 0; i < a.Length; i++)
{
if (a[i].Length == n)
{
p.Add(a[i]);
}
}
}
Console.WriteLine();
//File.Create(path1);
using (StreamWriter ff = File.AppendText(path1))
{
foreach (var k in p)
{
ff.WriteLine(k);
}
ff.Close();
Console.WriteLine(File.ReadAllText(path1));
}
}
}