You are on page 1of 7

#region Bài 1 - Nhập chuỗi S.

Ký tự hoa, thường
và ký số
//Console.WriteLine("Nhap chuoi:");
//string S = Console.ReadLine();
//int demhoa = 0;
//int demthuong = 0;
//int demso = 0;
//for (int i = 0; i < S.Length; i++)
//{
// if (Char.IsUpper(S[i]))
// {
// demhoa++;
// }
// else if (Char.IsLower(S[i]))
// {
// demthuong++;
// }
// else if (char.IsDigit(S[i]))
// {
// demso++;
// }
//}
//Console.WriteLine("Vay chuoi vua nhap co {0} chu hoa, {1} chu thuong, {2} ky
so",demhoa,demthuong,demso);
//Console.ReadKey();
#endregion

#region Bài 2 - Nhập chuỗi S. Chuỗi con


s1, s2. Thay thế tất cả chuỗi s1 thành chuỗi s2
trong chuỗi S
//Console.WriteLine("Nhap chuoi S:");
//string S = Console.ReadLine();
//Console.WriteLine("Nhap chuoi s1:");
//string s1 = Console.ReadLine();
//Console.WriteLine("Nhap chuoi s2:");
//string s2 = Console.ReadLine();
//string kq = S.Replace(s1, s2);
//Console.WriteLine("Chuoi da thay the la: " +kq);
#endregion
#region Bài 3 - Nhập chuỗi đầy đủ họ, tên
lót, tên. Tách và bỏ vô khoảng rộng 40 vị trí
//Console.WriteLine("Nhap day du ho va ten:" );
//string hoten = Console.ReadLine();
//string [] tachchuoi = hoten.Split(' ');
//string Ten = tachchuoi[tachchuoi.Length - 1];
//string kq = "";
//for (int i = 0; i < tachchuoi.Length-1; i++)
//{
// kq = kq + tachchuoi[i] + " ";
//}
//int khoangtrang = 40 - Ten.Length - kq.Length;
//string kt = "";
//for (int i = 0; i < khoangtrang; i++)
//{
// kt = kt + " ";
//}
//Console.WriteLine("Ket qua: " + kq + kt + Ten);
#endregion

#region Bài 4 - Đọc vào một chuỗi cho biết


chuỗi có bao nhiêu từ
//Console.WriteLine("Nhap chuoi:");
//string S = Console.ReadLine();
//string[] s = S.Split(' ');
//int demtu = 0;
//for (int i = 0; i < s.Length; i++)
//{
// if(s[i] != "")
// {
// demtu++;
// }
//}
//Console.WriteLine("Chuoi co {0} tu", demtu);
#endregion

#region Bài 5 - Đổi sang chuỗi chữ hoa


đầu mỗi từ
//Console.WriteLine("Nhap chuoi:");
//string S = Console.ReadLine();
//S = S.ToLower();
//string kq = "";
//string[] t = S.Split(' ');
//for (int i = 0; i < t.Length; i++)
//{
// char dau = t[i][0];
// dau = char.ToUpper(dau);
// string cuoi = t[i].Substring(1);
// string ghep = dau + cuoi;
// kq = kq + ghep + " ";
//}
//Console.WriteLine("Vay ket qua la: " + kq);
#endregion

#region Bài 6 - Cắt bỏ những khoảng trống


thừa trong chuỗi
//Console.WriteLine("Nhap chuoi:");
//string chuoi = Console.ReadLine();
//string[] S = chuoi.Split(' ');
//string kq = "";
//for (int i = 0; i < S.Length; i++)
//{
// if (S[i] != "")
// {
// kq = kq + S[i] + " ";
// }
//}
//Console.WriteLine(kq);
#endregion

#region Bài 7 - Chuỗi nhiều câu, các câu


cách nhau bởi dấu (.). In ra mỗi câu trên một dòng
//Console.WriteLine("Nhap chuoi:");
//string chuoi = Console.ReadLine();
//string[] S = chuoi.Split('.');
//for (int i = 0; i < S.Length; i++)
//{
// Console.WriteLine(S[i]);
//}
#endregion
#region Bài 8 - Các câu cách nhau bởi dấu
(.). Cho biết bao nhiêu câu. Câu dài nhất bao
nhiêu từ
//Console.WriteLine("Nhap chuoi:");
//string chuoi = Console.ReadLine();
//string[] cau = chuoi.Split(". ");
//int max = 0;
////Câu dài nhất
////Đếm số từ trong một câu, lưu lại vào 1 dãy mảng.
//int[] mangsotu =new int [cau.Length] ;
//for (int i = 0; i < cau.Length; i++)
//{
// string [] luutam = cau[i].Split(' ');
// int sotu = luutam.Length;
// mangsotu[i] = sotu;
//}
//for (int i = 0; i < mangsotu.Length; i++)
//{
// if(max < mangsotu[i])
// {
// max = mangsotu[i];
// }
//}
////In kqua
//Console.WriteLine("Chuoi co {0} cau. Cau dai nhat co {1} tu", cau.Length, max);
#endregion

#region Bài 9 - Có bao nhiêu câu. Câu dài


nhất bao nhiêu ký tự.
//Console.WriteLine("Nhap chuoi:");
//string chuoi = Console.ReadLine();
//string[] cau = chuoi.Split(". ");
//int max = 0;
////Câu dài nhất
////Đếm số từ trong một câu, lưu lại vào 1 dãy mảng.
//int[] mangsotu = new int[cau.Length];
//for (int i = 0; i < cau.Length; i++)
//{
// if (max < cau[i].Length)
// {
// max = cau[i].Length;
// }
//}
////In kqua
//Console.WriteLine("Chuoi co {0} cau. Cau dai nhat co {1} ky tu", cau.Length, max);
#endregion

#region Bài 10 - Cho biết tần suất xuất


hiện của các ký tự trong chuỗi.
string str1; //khai bao chuoi ban dau
string chuoi_con; //khai bao chuoi con can tim
int strt = 0;
int cnt = -1;
int idx = -1;
Console.Write("Nhap chuoi ban dau: ");
str1 = Console.ReadLine();
Console.Write("Nhap chuoi con can tim: ");
chuoi_con = Console.ReadLine();

while (strt != -1)


{
strt = str1.IndexOf(chuoi_con, idx + 1);
cnt += 1;
idx = strt;
}
Console.Write("Chuoi con '{0}' xuat hien " + cnt + " lan.\n", chuoi_con);

Console.ReadKey();

#region Bài 11 - Ma trận vuông. In các


chuỗi theo hàng, theo cột
//Console.WriteLine("Nhap so cap cua ma tran vuong: ");
//int n = int.Parse(Console.ReadLine());
//string[,] a = new string [n, n];
//for (int i = 0; i < n; i++)
//{
// for (int j = 0; j < n; j++)
// {
// Console.WriteLine("Nhap gia tri: ");
// a[i, j] = Console.ReadLine();
// }
//}
//Console.WriteLine("Mang da nhap la:");
//for (int i = 0; i < n; i++)
//{
// for (int j = 0; j < n; j++)
// {
// Console.Write( a[i,j]);
// }
// Console.WriteLine("");
//}
////In theo hàng ngang
//Console.WriteLine("In theo hang:");
//for (int i = 0; i < n; i++)
//{
// for (int j = 0; j < n; j++)
// {
// Console.Write(a[i,j] + " ");
// }
// Console.WriteLine("");
//}
//// In theo cột
//Console.WriteLine("In theo cot: ");
//for (int i = 0; i < n; i++)
//{
// for (int j = 0; j < n; j++)
// {
// Console.Write(a[j, i] + " ");
// }
// Console.WriteLine("");
//}
#endregion

#region Bai 1: Kiem tra Vong Lap


//Console.Write("Nhap n: ");
//int n = int.Parse(Console.ReadLine());
//Console.SetCursorPosition(0, 1);
//Console.Write("1");
//Console.SetCursorPosition(0, 2);
//Console.Write("{0}", n);
//for (int i = 2; i <= n; i++)
//{
// if (i % 2 == 0)
// {
// Console.SetCursorPosition((i - 1) * 4, 1);
// Console.Write("{0}", i * n);
// Console.SetCursorPosition((i - 1) * 4, 2);
// Console.Write("{0}", (n + 1) * (i - 1));
// }
// else
// {
// Console.SetCursorPosition((i - 1) * 4, 1);
// Console.Write("{0}", (n + 1) * i);
// Console.SetCursorPosition((i - 1) * 4, 2);
// Console.Write("{0}", i * n);
// }
//}
#endregion

You might also like