Skip to content

Commit

Permalink
Merge pull request #291 from ikesnowy/Dev-2.1
Browse files Browse the repository at this point in the history
2.1 Completed
  • Loading branch information
ikesnowy authored Jan 2, 2018
2 parents 41520a9 + 09cf394 commit 06cefb0
Show file tree
Hide file tree
Showing 356 changed files with 143,408 additions and 325 deletions.
7 changes: 6 additions & 1 deletion 1 Fundamental/1.1/1.1.10/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ static void Main(string[] args)
int[] a;
for (int i = 0; i < 10; i++)
{
a[i] = i * i; // 不允许使用未赋值的局部变量
// a[i] = i * i; // 不允许使用未赋值的局部变量
}
a = new int[10];
for (int i = 0; i < 10; i++)
{
a[i] = i * i; // 初始化后可用
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion 1 Fundamental/1.1/1.1.14/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static int lg(int N)
int pow = 1;
int sum = 2;

for (pow = 1; sum < N; ++pow)
for (pow = 1; sum < N; pow++)
{
sum *= baseNumber;
}
Expand Down
6 changes: 3 additions & 3 deletions 1 Fundamental/1.1/1.1.15/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ static void Main(string[] args)
{
int[] a = new int[10];
int M = 10;
for (int i = 0; i < 10; ++i)
for (int i = 0; i < 10; i++)
{
a[i] = i;
}
Expand All @@ -34,13 +34,13 @@ static int[] Histogram(int[] a, int M)
{
int[] result = new int[M];

for (int i = 0; i < M; ++i)
for (int i = 0; i < M; i++)
{
// 初始化
result[i] = 0;

// 遍历数组,计算数组中值为 i 的元素个数
for (int j = 0; j < a.Length; ++j)
for (int j = 0; j < a.Length; j++)
{
if (a[j] == i) // 值为 i 的元素
{
Expand Down
2 changes: 1 addition & 1 deletion 1 Fundamental/1.1/1.1.19/Fibnacci.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void Main(string[] args)
*
*/
Stopwatch timer = Stopwatch.StartNew();
for (int N = 0; N < 100; ++N)
for (int N = 0; N < 100; N++)
{
// 书本中的代码,非常慢,1小时后 N = 50
// Console.WriteLine($"{N} {F(N)}");
Expand Down
4 changes: 2 additions & 2 deletions 1 Fundamental/1.1/1.1.21/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ static void Main(string[] args)
int[,] array = new int[rows, columns]; // 输入的两个整数
double[] results = new double[rows]; // 计算结果

for (int i = 0; i < rows; ++i)
for (int i = 0; i < rows; i++)
{
string temp = Console.ReadLine();
names[i] = temp.Split(' ')[0];
for (int j = 0; j < columns; ++j)
for (int j = 0; j < columns; j++)
{
array[i, j] = int.Parse(temp.Split(' ')[j + 1]);
}
Expand Down
2 changes: 1 addition & 1 deletion 1 Fundamental/1.1/1.1.22/BinarySearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static int rank(int key, int[] a)
public static int rank(int key, int[] a, int lo, int hi, int number)
{

for (int i = 0; i < number; ++i)
for (int i = 0; i < number; i++)
{
Console.Write(" ");
}
Expand Down
4 changes: 2 additions & 2 deletions 1 Fundamental/1.1/1.1.23/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static void Main(string[] args)
string[] whiteList = File.ReadAllLines("largeW.txt");
int[] WhiteList = new int[whiteList.Length];

for (int i = 0; i < whiteList.Length; ++i)
for (int i = 0; i < whiteList.Length; i++)
{
WhiteList[i] = int.Parse(whiteList[i]);
}
Expand All @@ -29,7 +29,7 @@ static void Main(string[] args)
// 输入样例:5 824524 478510 387221
string input = Console.ReadLine();
int[] Query = new int[input.Split(' ').Length];
for (int i = 0; i < Query.Length; ++i)
for (int i = 0; i < Query.Length; i++)
{
Query[i] = int.Parse(input.Split(' ')[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions 1 Fundamental/1.1/1.1.28/BinarySearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void Main(string[] args)
h.CopyTo(whiteList);
int[] WhiteList = new int[whiteList.Length];

for (int i = 0; i < whiteList.Length; ++i)
for (int i = 0; i < whiteList.Length; i++)
{
WhiteList[i] = int.Parse(whiteList[i]);
}
Expand All @@ -33,7 +33,7 @@ static void Main(string[] args)
// 输入样例:5 824524 478510 387221
string input = Console.ReadLine();
int[] Query = new int[input.Split(' ').Length];
for (int i = 0; i < Query.Length; ++i)
for (int i = 0; i < Query.Length; i++)
{
Query[i] = int.Parse(input.Split(' ')[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion 1 Fundamental/1.1/1.1.29/BinarySearch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static void Main(string[] args)
Console.WriteLine("Type the numbers you want to query: ");
string input = Console.ReadLine();
int[] Query = new int[input.Split(' ').Length];
for (int i = 0; i < Query.Length; ++i)
for (int i = 0; i < Query.Length; i++)
{
Query[i] = int.Parse(input.Split(' ')[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions 1 Fundamental/1.1/1.1.30/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ static void Main(string[] args)

bool[,] a = new bool[N, N];

for (int i = 0; i < N; ++i)
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; ++j)
for (int j = 0; j < N; j++)
{
a[i, j] = (gcd(i, j) == 1);
}
Expand Down
6 changes: 3 additions & 3 deletions 1 Fundamental/1.1/1.1.31/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static void StartDrawing(int N, double p)
points[0].X = rect.Left + rect.Width / 2;
points[0].Y = rect.Top;

for (int i = 1; i < N; ++i)
for (int i = 1; i < N; i++)
{
points[i] = Rotate(Center, points[i - 1], rotateDgree);
}
Expand All @@ -72,9 +72,9 @@ public static void StartDrawing(int N, double p)

// 按照概率绘制直线
Random random = new Random();
for (int i = 0; i < N; ++i)
for (int i = 0; i < N; i++)
{
for (int j = i + 1; j < N; ++j)
for (int j = i + 1; j < N; j++)
{
// 举例:输入概率为 0.6,精度为 1000
// 在 0~1000 范围内等概率取值,如果小于等于 600 则视为事件发生
Expand Down
18 changes: 9 additions & 9 deletions 1 Fundamental/1.1/1.1.32/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private void button1_Click(object sender, EventArgs e)
//选择文件
openfiledialog.OpenFile();
//修改路径框显示
InputFilePath.Text = openfiledialog.FileName;
this.InputFilePath.Text = openfiledialog.FileName;
}
catch (Exception ex)
{
Expand All @@ -43,34 +43,34 @@ private void button2_Click(object sender, EventArgs e)
try
{
//打开文件并读取全部数字
string[] stringNums = File.ReadAllLines(InputFilePath.Text);
string[] stringNums = File.ReadAllLines(this.InputFilePath.Text);
//建立 double 数组
double[] Numbers = new double[stringNums.Length];
//将数字从 string 转换为 double
for (int i = 0; i < stringNums.Length; ++i)
for (int i = 0; i < stringNums.Length; i++)
{
Numbers[i] = double.Parse(stringNums[i]);
}

try
{
int N = int.Parse(InputN.Text);
int N = int.Parse(this.InputN.Text);
if (N <= 0)
{
ErrorLabel.Text = "N 必须大于 0";
this.ErrorLabel.Text = "N 必须大于 0";
return;
}
double L = double.Parse(InputL.Text);
double R = double.Parse(InputR.Text);
double L = double.Parse(this.InputL.Text);
double R = double.Parse(this.InputR.Text);
Program.StartDrawing(Numbers, N, L, R);
}
catch (FormatException fex)
{
ErrorLabel.Text = "格式有误(是否漏填了某项?)" + fex.Message;
this.ErrorLabel.Text = "格式有误(是否漏填了某项?)" + fex.Message;
}
catch (OverflowException oex)
{
ErrorLabel.Text = "数据过大(输入的内容太多)" + oex.Message;
this.ErrorLabel.Text = "数据过大(输入的内容太多)" + oex.Message;
}
}
catch (Exception ex)
Expand Down
6 changes: 3 additions & 3 deletions 1 Fundamental/1.1/1.1.32/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public static void StartDrawing(double[] array, int N, double l, double r)
// 计算各区域的值
int[] counts = new int[N];
int index = 0;
for (int i = 0; i < N; ++i)
for (int i = 0; i < N; i++)
{
for (int j = index; j < array.Length; ++j)
for (int j = index; j < array.Length; j++)
{
if (array[j] <= (r - l) * (i + 1) / N)
{
Expand All @@ -79,7 +79,7 @@ public static void StartDrawing(double[] array, int N, double l, double r)
rects[0].Y = 0;
rects[0].Width = (int)(2 * unit);
rects[0].Height = (int)((counts[0] / max) * DrawPad.Height);
for (int i = 1; i < N; ++i)
for (int i = 1; i < N; i++)
{
rects[i].X = (int)(rects[i - 1].X + 3 * unit);
rects[i].Y = 0;
Expand Down
24 changes: 12 additions & 12 deletions 1 Fundamental/1.1/1.1.33/Matrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static double Dot(double[] x, double[] y)

// 点乘
double result = 0;
for (int i = 0; i < x.Length; ++i)
for (int i = 0; i < x.Length; i++)
{
result += x[i] * y[i];
}
Expand Down Expand Up @@ -54,16 +54,16 @@ public static double[][] Mult(double[][] a, double[][] b)

double[][] result = new double[m][];

for (int i = 0; i < m; ++i)
for (int i = 0; i < m; i++)
{
double[] resultrow = new double[n];
for (int j = 0; j < n; ++j)
for (int j = 0; j < n; j++)
{
// result[i][j] = 行向量 a[i] 与列向量 b[j] 的点积
double[] row = a[i];
double[] col = new double[p];
// 取得列向量
for (int k = 0; k < p; ++k)
for (int k = 0; k < p; k++)
{
col[k] = b[k][j];
}
Expand All @@ -83,10 +83,10 @@ public static double[][] Mult(double[][] a, double[][] b)
public static double[][] Transpose(double[][] a)
{
double[][] trans = new double[a[0].Length][];
for (int i = 0; i < a[0].Length; ++i)
for (int i = 0; i < a[0].Length; i++)
{
double[] row = new double[a.GetLength(0)];
for (int j = 0; j < a.GetLength(0); ++j)
for (int j = 0; j < a.GetLength(0); j++)
{
row[j] = a[j][i];
}
Expand All @@ -111,7 +111,7 @@ public static double[] Mult(double[][] a, double[] x)

double[] result = new double[a.GetLength(0)];

for (int i = 0; i < a.GetLength(0); ++i)
for (int i = 0; i < a.GetLength(0); i++)
{
result[i] = Dot(a[i], x);
}
Expand All @@ -135,10 +135,10 @@ public static double[] Mult(double[] x, double[][] a)

double[] result = new double[a[0].Length];

for (int i = 0; i < a[0].Length; ++i)
for (int i = 0; i < a[0].Length; i++)
{
double[] colVector = new double[a.GetLength(0)];
for (int j = 0; j < colVector.Length; ++j)
for (int j = 0; j < colVector.Length; j++)
{
colVector[j] = a[j][i];
}
Expand All @@ -154,9 +154,9 @@ public static double[] Mult(double[] x, double[][] a)
/// <param name="a">需要输出的矩阵。</param>
public static void PrintMatrix(double[][] a)
{
for (int i = 0; i < a.GetLength(0); ++i)
for (int i = 0; i < a.GetLength(0); i++)
{
for (int j = 0; j < a[i].Length; ++j)
for (int j = 0; j < a[i].Length; j++)
{
Console.Write($"\t{a[i][j]}");
}
Expand All @@ -170,7 +170,7 @@ public static void PrintMatrix(double[][] a)
/// <param name="a">需要输出的向量。</param>
public static void PrintVector(double[] a)
{
for (int i = 0; i < a.Length; ++i)
for (int i = 0; i < a.Length; i++)
{
Console.Write($"\t{a[i]}");
}
Expand Down
16 changes: 8 additions & 8 deletions 1 Fundamental/1.1/1.1.34/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ static void Main(string[] args)
int N = AllNumbers.Length;
int[] input = new int[N];

for (int i = 0; i < N; ++i)
for (int i = 0; i < N; i++)
{
input[i] = int.Parse(AllNumbers[i]);
}
Expand Down Expand Up @@ -69,7 +69,7 @@ static void MinAndMax(int[] input)
int max = input[0];

// 只对输入值正向遍历一遍,不需要保存
for (int i = 1; i < input.Length; ++i)
for (int i = 1; i < input.Length; i++)
{
if (input[i] > max)
{
Expand Down Expand Up @@ -113,7 +113,7 @@ static int NumberK(int k, int[] input)
int[] temp = new int[101];

// 只正向遍历一遍,不需要保存
for (int i = 0; i < input.Length; ++i)
for (int i = 0; i < input.Length; i++)
{
if (i < 100)
{
Expand Down Expand Up @@ -141,7 +141,7 @@ static long SquareSum(int[] input)
{
long sum = 0;
// 只正向遍历一遍,不需要保存
for (int i = 0; i < input.Length; ++i)
for (int i = 0; i < input.Length; i++)
{
sum += input[i] * input[i];
}
Expand All @@ -162,7 +162,7 @@ static double Average(int[] input)
long sum = 0;

// 只遍历一遍,且不保存整个数组
for (int i = 0; i < input.Length; ++i)
for (int i = 0; i < input.Length; i++)
{
sum += input[i];
}
Expand All @@ -186,7 +186,7 @@ static double AboveAverage(int[] input)
Console.WriteLine();
double count = 0;

for (int i = 0; i < input.Length; ++i)
for (int i = 0; i < input.Length; i++)
{
if (input[i] > ave)
{
Expand All @@ -209,7 +209,7 @@ static void Ascending(int[] input)
Array.Sort(input);

Console.WriteLine("Ascending:");
for (int i = 0; i < input.Length; ++i)
for (int i = 0; i < input.Length; i++)
{
Console.Write($" {input[i]}");
}
Expand All @@ -228,7 +228,7 @@ static void Shuffle(int[] input)
int temp = 0;

Console.WriteLine("Shuffle:");
for (int i = 0; i < N; ++i)
for (int i = 0; i < N; i++)
{
temp = random.Next(0, All.Count - 1);
Console.Write($" {All[temp]}");
Expand Down
Loading

0 comments on commit 06cefb0

Please sign in to comment.