From c32c114c66797d39c9871ffd84e5f27c6255a239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=94=BF?= <1833662061@qq.com> Date: Wed, 26 Feb 2025 14:30:05 +0000 Subject: [PATCH 1/2] hello world MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张政 <1833662061@qq.com> --- Program.cs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Program.cs diff --git a/Program.cs b/Program.cs new file mode 100644 index 00000000..c448b490 --- /dev/null +++ b/Program.cs @@ -0,0 +1,2 @@ + +Console.WriteLine("Hello, World!"); -- Gitee From 9a28c048b393b7994a03a8bf1fc52f53eef1ac04 Mon Sep 17 00:00:00 2001 From: sjytjgw0830 <565033449@qq.com> Date: Sun, 16 Mar 2025 12:04:37 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=AE=9E=E9=AA=8C1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\345\256\236\351\252\2141.cs" | 208 ++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 "\351\202\223\347\232\223\346\226\207/\345\256\236\351\252\2141.cs" diff --git "a/\351\202\223\347\232\223\346\226\207/\345\256\236\351\252\2141.cs" "b/\351\202\223\347\232\223\346\226\207/\345\256\236\351\252\2141.cs" new file mode 100644 index 00000000..15d0f914 --- /dev/null +++ "b/\351\202\223\347\232\223\346\226\207/\345\256\236\351\252\2141.cs" @@ -0,0 +1,208 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Xml.Serialization; +class program +{ + static void Test01(){ + int x=int.Parse(Console.ReadLine()); + int y=int.Parse(Console.ReadLine()); + x = x + y; + y = x - y; + x = x - y; + + Console.WriteLine("x={0},y={1}",x,y); +} + static void Test02(ref int x,ref int y) + { + x = x + y; + y = x - y; + x = x - y; + } + static void Test03(int a, int b, out int sum, out int difference, out int product, out double quotient) + { + sum = a + b; + difference = a - b; + product = a * b; + if (b != 0) + { quotient = (double)a / b; } + else { quotient = double.NaN; } + } + + static void Test04() + { + + int max = FindMax(10, 20, 5, 30, 15); + + + Console.WriteLine("Test04 - 最大值: {0}", max); + } + + + static int FindMax(params int[] numbers) + { + if (numbers.Length == 0) + { + Console.WriteLine("至少需要提供一个参数"); + } + + int max = numbers[0]; + foreach (int num in numbers) + { + if (num > max) + { + max = num; + } + } + return max; + } + static void Test05() + { + + int sum = fbnq(20); + + + Console.WriteLine("Test05 - 斐波那契数列前20项的和: {0}", sum); + } + + + static int fbnq(int n) { + + if (n <= 0) + { + throw new ArgumentException("n 必须大于 0"); + } + + int a = 0, b = 1, sum = 0; + + for (int i = 0; i < n; i++) + { + sum += a; + int temp = a; + a = b; + b = temp + b; + } + + return sum; + } + static void Test06() + { + int N = 10; + int[,] arr = new int[N,N]; + for (int i = 0; i < N; i++) + { + arr[i, 0] = 1; + arr[i, i] = 1; + } + for (int i = 2; i < N; i++) + { + for (int j = 1; j < i; j++) + { + arr[i, j] = arr[i - 1, j - 1] + arr[i - 1, j]; + } + } + for (int i = 0; i < N; i++) + { + + for (int j = 0; j < N - i - 1; j++) + { + Console.Write(" "); + } + + + for (int j = 0; j <= i; j++) + { + Console.Write(arr[i, j] + " "); + } + + + Console.WriteLine(); + } + } + static void My_sort(int[] arr,int l,int r) + { if (l >= r) return; + int x=arr[(l+r)/2]; + int i = l - 1; + int j = r + 1; + while (i x); + if (i < j) Test02(ref arr[i], ref arr[j]); + } + My_sort(arr,l,j); + My_sort(arr,j+1,r); + } + static void Test07() + { + int[] arr = { 20, 16, 78, 61, 12, 99, 57, 34, 8 }; + My_sort(arr,0,8); + foreach(int i in arr) + { + Console.WriteLine(i); + } + } + static void Test08() + { + Listarr=new List(); + Listposition = new List(); + arr.Add("患者:“大夫,我咳嗽得很重。” 大夫:“你多大年记?” 患者:“七十五岁。” 大夫:“二十岁咳嗽吗”患者:“不咳嗽。” 大夫:“四十岁时咳嗽吗?” 患者:“也不咳嗽。” 大夫:“那现在不咳嗽,还要等到什么时咳嗽?"); + string keyword = "咳嗽"; + int index = 0; + while ((index = arr[0].IndexOf(keyword,index)) != -1) + { + position.Add(index); + index += keyword.Length; + } + Console.WriteLine($"关键字 '{keyword}' 出现了 {position.Count} 次。"); + Console.WriteLine("出现的位置如下:"); + foreach (int pos in position) + { + Console.WriteLine($"位置: {pos}"); + } + } + static void Test09() + { + string dateStr = "2020年10月1日"; + int yearIndex = dateStr.IndexOf("年"); + int monthIndex = dateStr.IndexOf("月"); + int dayIndex = dateStr.IndexOf("日"); + string year = dateStr.Substring(0, yearIndex); + string month = dateStr.Substring(yearIndex + 1, monthIndex - yearIndex - 1); + string day = dateStr.Substring(monthIndex + 1, dayIndex - monthIndex - 1); + Console.WriteLine($"年: {year}"); + Console.WriteLine($"月: {month}"); + Console.WriteLine($"日: {day}"); + } + static void Test10() + { + string input = " Hello World ! 你好 世界 ! "; + string trimmed = input.Trim(); + StringBuilder result = new StringBuilder(); + bool pre = false; + + foreach (char c in trimmed) + { + if (c == ' ') + { + if (!pre) + { + result.Append(c); + pre = true; + } + } + else + { + result.Append(c); + pre = false; + } + } + Console.WriteLine($"原始字符串: \"{input}\""); + Console.WriteLine($"处理后的字符串: \"{result.ToString()}\""); + } + + static void Main(string[] args) + { + Test08(); + } +} -- Gitee