Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Поле дураков
// 123 //Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { static byte[,] color_matrix; public static void Main(string[] args) { //byte[,] color_matrix; int n = 5; int m = 7; color_matrix = new byte[n, m]; color_matrix[0, 0] = 1; color_matrix[n - 1, m - 1] = 1; int[,] field = GenerateMatrix(n, m); int[,] field_value = ValueMatrix(field); int result = RoadMoney(field, field_value); WriteMatrixOfColor(field); Console.ResetColor(); Console.WriteLine("-----------------------"); WriteMatrixOfColor(field_value); Console.ResetColor(); Console.WriteLine("-----------------------"); Console.ResetColor(); Console.WriteLine("{0}", result); ; Console.ReadKey(); } static public int[,] GenerateMatrix (int n, int m) { Random rand = new Random(DateTime.Now.Millisecond); int[,] matrix = new int[n, m]; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) matrix[i, j] = rand.Next(1, 10); return matrix; } static public int[,] CreateMatrix(int n, int m) { int[,] matrix = new int[n, m]; for (int i = 0; i < n; i++) { string s1 = Console.ReadLine(); for (int j = 0; j < m; j++) matrix[i, j] = int.Parse(s1.Split()[j]); } return matrix; } static public void WriteMatrix(int[,] matrix) { int n = matrix.GetLength(0); int m = matrix.GetLength(1); for (int i = 0; i < n; i++) { for (int j = 0; j < m - 1; j++) { Console.Write(" {0:00} ", matrix[i, j]); } Console.WriteLine(" {0:00}", matrix[i, m - 1]); } } static public void WriteMatrixOfColor(int[,] matrix) { int n = matrix.GetLength(0); int m = matrix.GetLength(1); for (int i = 0; i < n; i++) { for (int j = 0; j < m - 1; j++) { if (color_matrix[i, j] == 1) Console.ForegroundColor = ConsoleColor.Red; else Console.ResetColor(); Console.Write("{0:0000} ", matrix[i, j]); } if (color_matrix[i, m - 1] == 1) Console.ForegroundColor = ConsoleColor.Red; else Console.ResetColor(); Console.WriteLine("{0:0000}", matrix[i, m - 1]); } } static public int[,] ValueMatrix(int[,] matrix) { int i0 = 0, j0 = 0, ij0 = 0; int n = matrix.GetLength(0); int m = matrix.GetLength(1); int[,] value_matrix = new int[n,m]; for (int i = n-1; i > -1; i--) { for (int j = m-1; j > -1; j--) { i0 = (i < n - 1) ? matrix[i + 1, j] : 0; j0 = (j < m - 1) ? matrix[i, j + 1] : 0; ij0 = (i < n - 1 && j < m - 1) ? matrix[i + 1, j + 1] : 0; value_matrix[i, j] = matrix[i, j] + i0 + j0 + ij0; } } return value_matrix; } static public int RoadMoney(int[,] matrix, int[,] value_matrix) { int n = matrix.GetLength(0); int m = matrix.GetLength(1); int i = 0, j = 0; int res = matrix[n-1,m-1]; for (int k = 0; k < n+m-2; k++) { if (i == n - 1) { res += matrix[i, j + 1]; j++; color_matrix[i, j] = 1; break; } if (j == m - 1) { res += matrix[i + 1, j]; i++; color_matrix[i, j] = 1; break; } if (value_matrix[i+1,j] > value_matrix[i,j+1]) { res += matrix[i + 1, j]; i++; } else { res += matrix[i, j + 1]; j++; } color_matrix[i, j] = 1; } res += matrix[n-1, m-1]; return res; } } }
run
|
edit
|
history
|
help
0
Reflection custom test
Create id
string formater placehoder
C# - MD5Hash
String to keycode and switch check
Customer bill information
asxsdf
PYRAMIDPATTERN
Brainf*ck interpreter
axasxasd