using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace Calc24Points { public class Cell { public enum Type { Number, Signal } public int Number; public char Signal; public Type Typ; public Cell Right; public Cell Left; /// <summary> /// 符号优先级 /// </summary> public int Priority { get { if (Typ == Type.Signal) { switch (Signal) { case '+': return 0; case '-': return 0; case '*': return 1; case '/': return 1; default: return -1; } } return -1; } } /// <summary> /// 基本单元构造函数 /// </summary> /// <param name="t">单元类型,数值或符号</param> /// <param name="num">数值</param> /// <param name="sig">符号</param> public Cell(Type t, int num, char sig) { Right = null; Left = null; Typ = t; Number = num; Signal = sig; } public Cell() { Right = null; Left = null; Number = 0; Typ = Type.Number; } public Cell(Cell c) { Right = null; Left = null; Number = c.Number; Signal = c.Signal; Typ = c.Typ; } } public class Calc24Points { string m_exp; bool m_stop; Cell[] m_cell; int[] m_express; StringWriter m_string; public Calc24Points(int n1, int n2, int n3, int n4) { m_cell = new Cell[8]; m_cell[0] = new Cell(Cell.Type.Number, n1, '?'); m_cell[1] = new Cell(Cell.Type.Number, n2, '?'); m_cell[2] = new Cell(Cell.Type.Number, n3, '?'); m_cell[3] = new Cell(Cell.Type.Number, n4, '?'); m_cell[4] = new Cell(Cell.Type.Signal, 0, '+'); m_cell[5] = new Cell(Cell.Type.Signal, 0, '-'); m_cell[6] = new Cell(Cell.Type.Signal, 0, '*'); m_cell[7] = new Cell(Cell.Type.Signal, 0, '/'); m_stop = false; m_express = new int[7]; m_string = new StringWriter(); m_exp = null; } public override string ToString() { if (m_exp == null) { PutCell(0); m_exp = m_string.ToString(); } if (m_exp != "") return m_exp; return null; } /// <summary> /// 在第n位置放置一个单元 /// </summary> /// <param name="n"></param> void PutCell(int n) { if (n >= 7) { if (Calculate()) { m_stop = true; Formate(); } return; } int end = 8; if (n < 2) end = 4; for (int i = 0; i < end; ++i) { m_express[n] = i; if (CheckCell(n)) PutCell(n + 1); if (m_stop) break; } } /// <summary> /// 检查当前放置是否合理 /// </summary> /// <param name="n"></param> /// <returns></returns> bool CheckCell(int n) { int nums = 0, sigs = 0; for (int i = 0; i <= n; ++i) { if (m_cell[m_express[i]].Typ == Cell.Type.Number) ++nums; else ++sigs; } if (nums - sigs < 1) return false; if (m_cell[m_express[n]].Typ == Cell.Type.Number) //数值不能重复,但是符号可以重复 { for (int i = 0; i < n; ++i) if (m_express[i] == m_express[n]) return false; } if (n == 6) { if (nums != 4 || sigs != 3) return false; if (m_cell[m_express[6]].Typ != Cell.Type.Signal) return false; return true; } return true; } /// <summary> /// 计算表达式是否为24 /// </summary> /// <returns>返回值true为24,否则不为24</returns> bool Calculate() { double[] dblStack = new double[4]; int indexStack = -1; for (int i = 0; i < 7; ++i) { if (m_cell[m_express[i]].Typ == Cell.Type.Number) { ++indexStack; dblStack[indexStack] = m_cell[m_express[i]].Number; } else { switch (m_cell[m_express[i]].Signal) { case '+': dblStack[indexStack - 1] = dblStack[indexStack - 1] + dblStack[indexStack]; break; case '-': dblStack[indexStack - 1] = dblStack[indexStack - 1]-+ dblStack[indexStack]; break; case '*': dblStack[indexStack - 1] = dblStack[indexStack - 1] * dblStack[indexStack]; break; case '/': dblStack[indexStack - 1] = dblStack[indexStack - 1] / dblStack[indexStack]; break; } --indexStack; } } if (Math.Abs(dblStack[indexStack] - 24) < 0.1) return true; return false; } /// <summary> /// 后缀表达式到中缀表达式 /// </summary> void Formate() { Cell[] c = new Cell[7]; for (int i = 0; i < 7; ++i) c[i] = new Cell(m_cell[m_express[i]]); int[] cStack = new int[4]; int indexStack = -1; for (int i = 0; i < 7; ++i) { if (c[i].Typ == Cell.Type.Number) { ++indexStack; cStack[indexStack] = i; } else { c[i].Right = c[cStack[indexStack]]; --indexStack; c[i].Left = c[cStack[indexStack]]; cStack[indexStack] = i; } } ToStringFormate(c[cStack[indexStack]]); } void ToStringFormate(Cell root) { if (root.Left.Typ == Cell.Type.Number) { m_string.Write(root.Left.Number); m_string.Write(root.Signal); } else { if (root.Priority > root.Left.Priority) { m_string.Write("("); ToStringFormate(root.Left); m_string.Write(")"); } else ToStringFormate(root.Left); m_string.Write(root.Signal); } if (root.Right.Typ == Cell.Type.Number) m_string.Write(root.Right.Number); else { if (root.Priority >= root.Right.Priority) { m_string.Write("("); ToStringFormate(root.Right); m_string.Write(")"); } else ToStringFormate(root.Right); } } } }

C#.NETissuitableforenterprise-levelapplicationswithintheMicrosoftecosystemduetoitsstrongtyping,richlibraries,androbustperformance.However,itmaynotbeidealforcross-platformdevelopmentorwhenrawspeediscritical,wherelanguageslikeRustorGomightbepreferable.

The programming process of C# in .NET includes the following steps: 1) writing C# code, 2) compiling into an intermediate language (IL), and 3) executing by the .NET runtime (CLR). The advantages of C# in .NET are its modern syntax, powerful type system and tight integration with the .NET framework, suitable for various development scenarios from desktop applications to web services.

C# is a modern, object-oriented programming language developed by Microsoft and as part of the .NET framework. 1.C# supports object-oriented programming (OOP), including encapsulation, inheritance and polymorphism. 2. Asynchronous programming in C# is implemented through async and await keywords to improve application responsiveness. 3. Use LINQ to process data collections concisely. 4. Common errors include null reference exceptions and index out-of-range exceptions. Debugging skills include using a debugger and exception handling. 5. Performance optimization includes using StringBuilder and avoiding unnecessary packing and unboxing.

Testing strategies for C#.NET applications include unit testing, integration testing, and end-to-end testing. 1. Unit testing ensures that the minimum unit of the code works independently, using the MSTest, NUnit or xUnit framework. 2. Integrated tests verify the functions of multiple units combined, commonly used simulated data and external services. 3. End-to-end testing simulates the user's complete operation process, and Selenium is usually used for automated testing.

Interview with C# senior developer requires mastering core knowledge such as asynchronous programming, LINQ, and internal working principles of .NET frameworks. 1. Asynchronous programming simplifies operations through async and await to improve application responsiveness. 2.LINQ operates data in SQL style and pay attention to performance. 3. The CLR of the NET framework manages memory, and garbage collection needs to be used with caution.

C#.NET interview questions and answers include basic knowledge, core concepts, and advanced usage. 1) Basic knowledge: C# is an object-oriented language developed by Microsoft and is mainly used in the .NET framework. 2) Core concepts: Delegation and events allow dynamic binding methods, and LINQ provides powerful query functions. 3) Advanced usage: Asynchronous programming improves responsiveness, and expression trees are used for dynamic code construction.

C#.NET is a popular choice for building microservices because of its strong ecosystem and rich support. 1) Create RESTfulAPI using ASP.NETCore to process order creation and query. 2) Use gRPC to achieve efficient communication between microservices, define and implement order services. 3) Simplify deployment and management through Docker containerized microservices.

Security best practices for C# and .NET include input verification, output encoding, exception handling, as well as authentication and authorization. 1) Use regular expressions or built-in methods to verify input to prevent malicious data from entering the system. 2) Output encoding to prevent XSS attacks, use the HttpUtility.HtmlEncode method. 3) Exception handling avoids information leakage, records errors but does not return detailed information to the user. 4) Use ASP.NETIdentity and Claims-based authorization to protect applications from unauthorized access.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.