题解 | #小乐乐找最大数#
小乐乐找最大数
https://www.nowcoder.com/practice/ae6a21920cac4f9184c8ecfcc87f89b9
public class Program { public static void Main() { string[] line = System.Console.ReadLine().Split(" "); int[] arr = new int[line.Length]; for (int i = 0; i < line.Length; i++) { int Num = int.Parse(line[i]); arr[i] = Num; }; //Length-1是因为下标是从0开始的 for (int i = 0; i < arr.Length - 1; i++) { bool outflag = false; for (int j = 0; j < arr.Length - 1 - i; j++) { if (arr[j] > arr[j + 1]) { //交换两个临时变量,保存了谁的值就先换谁 int tmp = arr[j + 1]; arr[j + 1] = arr[j]; arr[j] = tmp; outflag = true; }; }; if (!outflag) break; }; System.Console.WriteLine(arr[line.Length - 1]); } }