Câu 1 - Tập tin (Ví dụ 1 & Ví dụ 2)
Ví dụ 1: Tách Họ - Tên lót - Tên
using System;
using [Link];
class Program
{
static void Main()
{
string inputPath = "[Link]";
string outputPath = "[Link]";
string[] lines = [Link](inputPath);
using (StreamWriter writer = new StreamWriter(outputPath))
{
foreach (string line in lines)
{
string[] parts = [Link]().Split(' ');
string ho = parts[0];
string ten = parts[[Link] - 1];
string tenLot = "";
for (int i = 1; i < [Link] - 1; i++)
{
tenLot += parts[i] + " ";
}
tenLot = [Link]();
[Link](line);
[Link]("- Ho: " + ho);
[Link]("- Ten lot: " + tenLot);
[Link]("- Ten: " + ten);
}
}
[Link]("Da xu ly xong Names!");
}
}
Ví dụ 2: Kiểm tra Password
using System;
using [Link];
class Program
{
static bool KiemTraPassword(string s)
{
if ([Link] < 8)
return false;
bool coChuThuong = false;
bool coChuHoa = false;
bool coSo = false;
foreach (char c in s)
{
if ([Link](c)) coChuThuong = true;
if ([Link](c)) coChuHoa = true;
if ([Link](c)) coSo = true;
}
return coChuThuong && coChuHoa && coSo;
}
static void Main()
{
string path;
while (true)
{
[Link]("Nhap duong dan file [Link]: ");
path = [Link]();
if ([Link](path))
break;
else
[Link]("File not found!");
}
string[] lines = [Link](path);
string outputPath = [Link](
[Link](path),
"[Link]"
);
using (StreamWriter writer = new StreamWriter(outputPath))
{
foreach (string line in lines)
{
bool hopLe = KiemTraPassword(line);
[Link](line + " : " + (hopLe ? "Yes" : "No"));
}
}
[Link]("Da kiem tra xong Password!");
}
}