diff --git a/LZQ/Program.cs b/LZQ/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..1bc52a60a8ba3f1f529a2cf3a5bc58595e785f6c --- /dev/null +++ b/LZQ/Program.cs @@ -0,0 +1 @@ +Console.WriteLine("Hello, World!"); diff --git a/Xzt/Program.cs b/Xzt/Program.cs new file mode 100644 index 0000000000000000000000000000000000000000..3751555cbd32d09340c8cb7b75ce8311c4330054 --- /dev/null +++ b/Xzt/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git "a/Zsx/\345\256\236\351\252\2141/1.cs" "b/Zsx/\345\256\236\351\252\2141/1.cs" new file mode 100644 index 0000000000000000000000000000000000000000..d22097af8ea6dc0d0f7e1f0724aca1f5db62c572 --- /dev/null +++ "b/Zsx/\345\256\236\351\252\2141/1.cs" @@ -0,0 +1,14 @@ +using System; +class Program +//不使用临时变量 +{ + static void Main() + { + int n1 = 10, n2 = 20; + Console.WriteLine($"n1={n1}, n2={n2}"); + n1 = n1 + n2; + n2 = n1 - n2; + n1 = n1 - n2; + Console.WriteLine($"n1={n1}, n2={n2}"); + } +} diff --git "a/Zsx/\345\256\236\351\252\2141/10.cs" "b/Zsx/\345\256\236\351\252\2141/10.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b7d216f908abf791e29d4926ffef658f2e0f457c --- /dev/null +++ "b/Zsx/\345\256\236\351\252\2141/10.cs" @@ -0,0 +1,16 @@ +using System; + +class StringFormatter +{ + static void Main() + { + string str = " Hello World! 你好 世界! "; + string result = ProcessString(str); + Console.WriteLine($"处理后:'{result}'"); + } + + static string ProcessString(string str) + { + return System.Text.RegularExpressions.Regex.Replace(str.Trim(), @"\s+", " "); + } +} diff --git "a/Zsx/\345\256\236\351\252\2141/11.cs" "b/Zsx/\345\256\236\351\252\2141/11.cs" new file mode 100644 index 0000000000000000000000000000000000000000..88c957fb2a229ac1cbd5847b93efafb682680da3 --- /dev/null +++ "b/Zsx/\345\256\236\351\252\2141/11.cs" @@ -0,0 +1,64 @@ +using System; + +class RockPaperScissors +{ + // 定义手势枚举类型 + public enum Gesture + { + 石头, + 剪刀, + 布 + } + + static void Main() + { + Random rand = new Random(); + int userScore = 0, computerScore = 0; + Gesture[] validGestures = (Gesture[])Enum.GetValues(typeof(Gesture)); // 获取所有枚举值 + + while (true) + { + Console.Write("请输入您的选择(石头/剪刀/布)或输入'退出'结束游戏:"); + string input = Console.ReadLine().Trim(); + + if (input.Equals("退出", StringComparison.OrdinalIgnoreCase)) + { + Console.WriteLine($"游戏结束!最终比分:玩家 {userScore} - {computerScore} 电脑"); + break; + } + + // 显式指定枚举类型参数 + if (!Enum.TryParse(input, true, out Gesture gesture) || + !Enum.IsDefined(typeof(Gesture), gesture)) + { + Console.WriteLine("无效输入,请重新输入!"); + continue; + } + + int computerChoice = rand.Next(validGestures.Length); + Gesture computerGesture = validGestures[computerChoice]; + + Console.WriteLine($"您出了:{gesture} 电脑出了:{computerGesture}"); + + // 使用枚举比较提升可读性 + if (gesture == computerGesture) + Console.WriteLine("平局!"); + else if ( + (gesture == Gesture.石头 && computerGesture == Gesture.剪刀) || + (gesture == Gesture.剪刀 && computerGesture == Gesture.布) || + (gesture == Gesture.布 && computerGesture == Gesture.石头) + ) + { + Console.WriteLine("你赢了!"); + userScore++; + } + else + { + Console.WriteLine("电脑赢了!"); + computerScore++; + } + + Console.WriteLine($"当前比分:玩家 {userScore} - {computerScore} 电脑\n"); + } + } +} diff --git "a/Zsx/\345\256\236\351\252\2141/2.cs" "b/Zsx/\345\256\236\351\252\2141/2.cs" new file mode 100644 index 0000000000000000000000000000000000000000..742b7c72252afa8cc825c5dc579e2e931f0f62dd --- /dev/null +++ "b/Zsx/\345\256\236\351\252\2141/2.cs" @@ -0,0 +1,21 @@ +using System; + +class Program +{ + static void Main() + { + int n1 = 10, n2 = 20; + Console.WriteLine($"交换前:n1={n1}, n2={n2}"); + + // 调用Swap方法,通过ref参数直接交换原始变量 + Swap(ref n1, ref n2); + + Console.WriteLine($"交换后:n1={n1}, n2={n2}"); + } + static void Swap(ref int a, ref int b) + { + int temp = a; + a = b; + b = temp; + } +} diff --git "a/Zsx/\345\256\236\351\252\2141/3.cs" "b/Zsx/\345\256\236\351\252\2141/3.cs" new file mode 100644 index 0000000000000000000000000000000000000000..9963990feded23b1586b8fed6ea66267be7e9fba --- /dev/null +++ "b/Zsx/\345\256\236\351\252\2141/3.cs" @@ -0,0 +1,38 @@ +using System; + +class Calculator +{ + static void Main() + { + Console.WriteLine("请输入第一个整数a:"); + string inputA = Console.ReadLine(); + int a; + while (!int.TryParse(inputA, out a)) + { + + Console.WriteLine("输入的不是有效的整数,请重新输入a:"); + inputA = Console.ReadLine(); + } + + + Console.WriteLine("请输入第二个整数b:"); + string inputB = Console.ReadLine(); + int b; + while (!int.TryParse(inputB, out b)) + { + Console.WriteLine("输入的不是有效的整数,请重新输入b:"); + inputB = Console.ReadLine(); + } + int add, sub, mul, div; + Calculate(a, b, out add, out sub, out mul, out div); + Console.WriteLine($"结果是:{a}+{b}={add}, {a}-{b}={sub}, {a}*{b}={mul}, {a}/{b}={div}"); + } + + static void Calculate(int x, int y, out int add, out int sub, out int mul, out int div) + { + add = x + y; + sub = x - y; + mul = x * y; + div = y != 0 ? x / y : 0; + } +} diff --git "a/Zsx/\345\256\236\351\252\2141/4.cs" "b/Zsx/\345\256\236\351\252\2141/4.cs" new file mode 100644 index 0000000000000000000000000000000000000000..7f147d844d577b507f8f97943956edc8d2dc4a1a --- /dev/null +++ "b/Zsx/\345\256\236\351\252\2141/4.cs" @@ -0,0 +1,25 @@ +using System; + +class MaxValueFinder +{ + static void Main() + { + int[] numbers = { 12, 45, 7, 23, 55, 34 }; + // 遍历数组并打印每个元素 + foreach (int number in numbers) + { + Console.WriteLine(number); + } + int max = GetMax(numbers); + Console.WriteLine($"最大值:{max}"); + } + + static int GetMax(params int[] nums) + { + if (nums.Length == 0) throw new ArgumentException("数组不能为空"); + int max = nums[0]; + foreach (int num in nums) + if (num > max) max = num; + return max; + } +} diff --git "a/Zsx/\345\256\236\351\252\2141/5.cs" "b/Zsx/\345\256\236\351\252\2141/5.cs" new file mode 100644 index 0000000000000000000000000000000000000000..3b7107aa21172ecf4bbeaba7f5589b14136c0ce0 --- /dev/null +++ "b/Zsx/\345\256\236\351\252\2141/5.cs" @@ -0,0 +1,25 @@ +using System; + +class FibonacciSum +{ + static void Main() + { + int n = 20; + int sum = Fibonacci(n); + Console.WriteLine($"斐波那契前{n}项和:{sum}"); + } + + static int Fibonacci(int n) + { + if (n < 1) return 0; + int a = 0, b = 1, sum = 0; + for (int i = 1; i <= n; i++) + { + sum += b; + int temp = a; + a = b; + b = temp + b; + } + return sum; + } +} diff --git "a/Zsx/\345\256\236\351\252\2141/6.cs" "b/Zsx/\345\256\236\351\252\2141/6.cs" new file mode 100644 index 0000000000000000000000000000000000000000..3e60a84b11648bb1ad01c2b3e45f1e4361665339 --- /dev/null +++ "b/Zsx/\345\256\236\351\252\2141/6.cs" @@ -0,0 +1,30 @@ +using System; + +class YanghuiTriangle +{ + static void Main() + { + int rows = 10; + PrintYanghuiTriangle(rows); + } + + static void PrintYanghuiTriangle(int rows) + { + int[,] triangle = new int[rows, rows]; + for (int i = 0; i < rows; i++) + { + triangle[i, 0] = 1; + triangle[i, i] = 1; + for (int j = 1; j < i; j++) + triangle[i, j] = triangle[i - 1, j - 1] + triangle[i - 1, j]; + } + + for (int i = 0; i < rows; i++) + { + Console.Write(new string(' ', rows - i - 1)); + for (int j = 0; j <= i; j++) + Console.Write($"{triangle[i, j]} "); + Console.WriteLine(); + } + } +} diff --git "a/Zsx/\345\256\236\351\252\2141/7.cs" "b/Zsx/\345\256\236\351\252\2141/7.cs" new file mode 100644 index 0000000000000000000000000000000000000000..4547522dd087d57ff12248cd52b92c419e67a795 --- /dev/null +++ "b/Zsx/\345\256\236\351\252\2141/7.cs" @@ -0,0 +1,35 @@ +using System; + +class BubbleSort +{ + static void Main() + { + int[] arr = { 20, 16, 78, 61, 12, 99, 57, 34, 8 }; + foreach (int number in arr) + { + Console.WriteLine(number); + } + //打印原始数组 + Bubble(arr); + Console.WriteLine("排序结果:" + string.Join(", ", arr)); + } + + static void Bubble(int[] arr) + { + bool swapped; + for (int i = 0; i < arr.Length - 1; i++) + { + swapped = false; + for (int j = 0; j < arr.Length - 1 - i; j++) + if (arr[j] > arr[j + 1]) + { + int temp = arr[j]; + arr[j] = arr[j + 1]; + arr[j + 1] = temp; + swapped = true; + } + if (!swapped) break; + } + } +} + diff --git "a/Zsx/\345\256\236\351\252\2141/8.cs" "b/Zsx/\345\256\236\351\252\2141/8.cs" new file mode 100644 index 0000000000000000000000000000000000000000..b77e9abeb5686843e94a33ce4fbb4dd1bf9dbb9d --- /dev/null +++ "b/Zsx/\345\256\236\351\252\2141/8.cs" @@ -0,0 +1,18 @@ +using System; + +class CoughCounter +{ + static void Main() + { + string dialogue = "患者:“大夫,我咳嗽得很重。” 大夫:“你多大年记?” 患者:“七十五岁。” 大夫:“二十岁咳嗽吗”患者:“不咳嗽。” 大夫:“四十岁时咳嗽吗?” 患者:“也不咳嗽。” 大夫:“那现在不咳嗽,还要等到什么时咳嗽?”\"。"; + Console.WriteLine(dialogue); + int index = 0, count = 0; + while ((index = dialogue.IndexOf("咳嗽", index)) != -1) + { + count++; + Console.WriteLine($"第{count}次出现:位置{index}"); + index += 2; + } + Console.WriteLine($"总计出现:{count}次"); + } +} diff --git "a/Zsx/\345\256\236\351\252\2141/9.cs" "b/Zsx/\345\256\236\351\252\2141/9.cs" new file mode 100644 index 0000000000000000000000000000000000000000..521118aa4f48bb6f49b3450803cf1f5c5303a095 --- /dev/null +++ "b/Zsx/\345\256\236\351\252\2141/9.cs" @@ -0,0 +1,11 @@ +using System; + +class DateParser +{ + static void Main() + { + string dateStr = "2020年10月1日"; + string[] parts = dateStr.Split(new[] { '年', '月', '日' }, StringSplitOptions.None); + Console.WriteLine($"年:{parts[0]} 月:{parts[1]} 日:{parts[2]}"); + } +} diff --git a/dong/123.txt b/dong/123.txt new file mode 100644 index 0000000000000000000000000000000000000000..a6ca7a24a5c539a08efb2762aee67f2df728a814 --- /dev/null +++ b/dong/123.txt @@ -0,0 +1,10 @@ +#include + +using namespace std; + +int main() +{ + + + return 0; +} \ No newline at end of file diff --git a/lmr/helloworld.txt b/lmr/helloworld.txt new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391