public void Test_Number_Zero() { Solution3 solution = new Solution3(); bool status = (0 > 5); Assert.IsFalse(status); }
public void Test_Negative_Number() { Solution3 solution = new Solution3(); bool status = (-5 > 5); Assert.IsFalse(status); }
private void ShowSlnInfo() { StringBuilder info = new StringBuilder(); Solution3 sln = DTEObject.Solution as Solution3; SolutionNode sn = new SolutionNode { FileName = sln.FileName, FullName = sln.FullName }; foreach (Project proj in sln.Projects) { if (proj.Kind == ProjectKinds.vsProjectKindSolutionFolder) { AddSolutionFolder(sn, proj); //sn.SolutionFolderList.Add(); } else { AddProject(sn, proj); //info.AppendLine(proj.FullName); } } //MessageBox.Show(info.ToString()); Solution3 newSln = DTEObject.Solution as Solution3; newSln.Create(@"C:\solutions", "mySln"); MessageBox.Show(newSln.FullName); }
public void Test_Number_Greater_Than_Five() { Solution3 solution = new Solution3(); bool status = (10 > 5); Assert.IsTrue(status); }
public override void Run() { var root = Create(0, 1, 2, 3, 4, 5, 6); BTreePrinter.Print(root); Console.WriteLine("Solution 1"); var sol1 = new Solution1(); var result = sol1.Convert(root); Display(result.Head); Console.WriteLine("Solution 2"); root = Create(0, 1, 2, 3, 4, 5, 6); var sol2 = new Solution2(); var result2 = sol2.Convert(root); Display(result2); Console.WriteLine("Solution 3"); root = Create(0, 1, 2, 3, 4, 5, 6); var sol3 = new Solution3(); var result3 = sol3.Convert(root); Display(result3); }
private static int Solve3(string s) { var solution = new Solution3(); var result = solution.LengthOfLongestSubstring(s); return(result); }
public void Test_Number_Equal_To_Five() { Solution3 solution = new Solution3(); bool status = (5 > 5); Assert.IsFalse(status); }
public void CopyArray2() { var test = new int[] { 3, 8, 9, 7, 6 }; var result = new Solution3().solution(test, 6); Assert.That(result, Is.EquivalentTo(new [] { 9, 7, 6, 3, 8 })); }
static void Main(string[] args) { int[] input = { 20, 4, 8, 2 }; int nums = 4; Solution3 x = new Solution3(); x.minimumTime(nums, input); }
static void Main(string[] args) { int[] nums = { 1, 2, 1, 1, 1 }; Solution3 solution = new Solution3(); int ret = solution.Jump(nums); Console.WriteLine(ret); Console.ReadLine(); }
private static void Main(string[] args) { Console.WriteLine("Hello World!"); var nums = new int[] { 1, 2, 3 }; var s = new Solution3(); Console.WriteLine(s.Rob(nums)); }
private static void Main(string[] args) { Console.WriteLine("Hello World!"); var num = 10; var s = new Solution3(); Console.WriteLine(s.IntegerBreak(num)); }
private static void Main(string[] args) { Console.WriteLine("Hello World!"); //var prices = new int[] { 7, 1, 5, 3, 6, 4 }; var prices = new int[] { 1, 2, 3, 4, 5, 6 }; var s = new Solution3(); Console.WriteLine(s.MaxProfit(prices)); }
private static void Main(string[] args) { Console.WriteLine("Hello World!"); var coins = new int[] { 2 }; var amount = 3; var s = new Solution3(); Console.WriteLine(s.CoinChange(coins, amount)); }
private static void Main(string[] args) { Console.WriteLine("Hello World!"); var coins = new int[] { 1, 2, 5 }; var amount = 5; var s = new Solution3(); Console.WriteLine(s.Change(amount, coins)); }
private static void Main(string[] args) { Console.WriteLine("Hello World!"); var prices = new int[] { 1, 3, 2, 8, 4, 9 }; var fee = 2; var s = new Solution3(); Console.WriteLine(s.MaxProfit(prices, fee)); }
private static void Main(string[] args) { Console.WriteLine("Hello World!"); //var nums = new int[] { 2, 7, 4, 1, 8, 1 }; //var nums = new int[] { 31, 26, 33, 21, 40 }; var nums = new int[] { 6, 2, 2, 6, 5, 7, 7 }; var s = new Solution3(); Console.WriteLine(s.LastStoneWeightII(nums)); }
private static void Main(string[] args) { Console.WriteLine("Hello World!"); var haystack = "aaabcaaaaaabc"; var needle = "aabaaf"; var s = new Solution3(); Console.WriteLine(s.StrStr(haystack, needle)); }
private void frmMultiCreateProjects_Load(object sender, EventArgs e) { Solution3 sol3 = _app.Solution as Solution3; if (sol3 == null || string.IsNullOrEmpty(sol3.FileName)) { return; } string slnPath = Path.GetDirectoryName(sol3.FileName); this.txtSaveDir.Text = slnPath; this.txtRootDir.Text = Path.GetFileNameWithoutExtension(sol3.FileName); }
private static void Main(string[] args) { Console.WriteLine("Hello World!"); var text = "aaaaaaa"; var wordDict = new List <string> { "aaa", "aaaa" }; var s = new Solution3(); Console.WriteLine(s.WordBreak(text, wordDict)); }
public void SolutionThree_CompareResultsWithExpected() { Solution3 sol3 = new Solution3(); sol3.run(); JsonOutputObject actualJsonOutput = sol3.output; JsonOutputObject expectedJsonOutput = sol3.LoadExpectedOutput(); for (int i = 0; i < actualJsonOutput.carts.Count; i++) { Assert.AreEqual(actualJsonOutput.carts[i].id, expectedJsonOutput.carts[i].id); Assert.AreEqual(actualJsonOutput.carts[i].total, expectedJsonOutput.carts[i].total); } }
public void SolutionThree_VerifyAllCartIds() { Solution3 sol3 = new Solution3(); sol3.run(); JsonInputObject input = sol3.input; JsonOutputObject result = sol3.output; foreach (Cart inputCart in input.carts) { Assert.IsTrue(result.carts.Exists(x => x.id == inputCart.id)); } Assert.IsTrue(input.carts.Count == result.carts.Count); Assert.IsFalse(result.carts.Exists(x => x.id == 999)); }
static void Main(string[] args) { try { Solution1 sol1 = new Solution1(); sol1.run(); } catch (Exception ex) { Console.WriteLine(string.Format("Level 1 ERROR: {0}", ex.Message)); } finally { Console.WriteLine("Level 1 solved successfully"); } try { Solution2 sol2 = new Solution2(); sol2.run(); } catch (Exception ex) { Console.WriteLine(string.Format("Level 2 ERROR: {0}", ex.Message)); } finally { Console.WriteLine("Level 2 solved successfully"); } try { Solution3 sol3 = new Solution3(); sol3.run(); } catch (Exception ex) { Console.WriteLine(string.Format("Level 3 ERROR: {0}", ex.Message)); } finally { Console.WriteLine("Level 3 solved successfully"); } }
private void btnConvert_Click(object sender, EventArgs e) { // Create a sln Solution3 newSln = DTEObject.Solution as Solution3; newSln.Create(@"C:\solutions", "mySln"); // Add a proj string templatePath = newSln.GetProjectTemplate("ClassLibrary.zip", "CSharp"); newSln.AddFromTemplate(templatePath, @"C:\solutions\NewProj", "mySln.NewProj", false); Project proj = newSln.Projects.Item(1); VSProject2 vsProj = proj.Object as VSProject2; vsProj.References.Add(@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll"); // Save the sln newSln.SaveAs(@"C:\solutions\mySln.sln"); //newSln.Close(true); //ShowSlnInfo(); }
private void btnOK_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; Solution3 sol3 = _app.Solution as Solution3; if (sol3 == null || string.IsNullOrEmpty(sol3.FileName)) { MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案"); return; } List <Project> existProjs = ProjectUtility.GetAllProjects(_app); for (int i = 0; i < this.treeView1.Nodes.Count; i++) { TreeNode rootNode = this.treeView1.Nodes[i]; if (rootNode.Checked && rootNode.Nodes.Count > 0) { string foldName = rootNode.Tag as string; bool isExistFolder = false; for (int j = 1; j < sol3.Projects.Count; j++) { Project proj = sol3.Projects.Item(j); if (proj.Kind != ProjectKinds.vsProjectKindSolutionFolder) { continue; } if (sol3.Projects.Item(j).Name.Equals(foldName, StringComparison.CurrentCultureIgnoreCase)) { isExistFolder = true; break; } } if (isExistFolder == false) { Project solFolder = sol3.AddSolutionFolder(rootNode.Tag as string); } for (int j = 0; j < rootNode.Nodes.Count; j++) { if (rootNode.Nodes[j].Checked) { string projPath = rootNode.Nodes[j].Tag as string; bool isExist = false; for (int k = 0; k < existProjs.Count; k++) { if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase)) { isExist = true; break; } } if (isExist == false) { Project proj = sol3.AddFromFile(projPath, false); } else { MsgBox.ShowTip(Path.GetFileNameWithoutExtension(projPath) + "已经加载"); } } } } else { for (int j = 0; j < rootNode.Nodes.Count; j++) { if (rootNode.Nodes[j].Checked) { string projPath = rootNode.Nodes[j].Tag as string; bool isExist = false; for (int k = 0; k < existProjs.Count; k++) { if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase)) { isExist = true; break; } } if (isExist == false) { Project proj = sol3.AddFromFile(projPath, false); } else { MsgBox.ShowTip(Path.GetFileNameWithoutExtension(projPath) + "已经加载"); } } } } } this.DialogResult = System.Windows.Forms.DialogResult.OK; } catch (Exception ex) { MsgBox.ShowTip(ex.Message); } finally { this.Cursor = Cursors.Default; } }
public void Setup() { solver = new Solution3(); }
private void btnOK_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; Solution3 sol3 = _app.Solution as Solution3; if (sol3 == null || string.IsNullOrEmpty(sol3.FileName)) { MsgBox.ShowTip("请先打开已有解决方案或者新建一个解决方案"); return; } string saveDir = this.txtSaveDir.Text.Trim(); if (string.IsNullOrEmpty(saveDir) || Directory.Exists(saveDir) == false) { MsgBox.ShowTip("请选择项目保存位置"); return; } string rootDir = this.txtRootDir.Text.Trim(); rootDir = rootDir.TrimEnd('.'); if (string.IsNullOrEmpty(rootDir)) { MsgBox.ShowTip("根名字空间不能为空"); return; } bool isExistFolder = false; for (int j = 1; j < sol3.Projects.Count; j++) { Project proj = sol3.Projects.Item(j); if (proj.Kind != ProjectKinds.vsProjectKindSolutionFolder) { continue; } if (sol3.Projects.Item(j).Name.Equals(rootDir, StringComparison.CurrentCultureIgnoreCase)) { isExistFolder = true; break; } } if (isExistFolder == false) { Project solFolder = sol3.AddSolutionFolder(rootDir); } List <Project> existProjs = ProjectUtility.GetAllProjects(_app); for (int i = 0; i < this.richTextBox1.Lines.Length; i++) { string subDir = this.richTextBox1.Lines[i].Trim(); subDir = subDir.TrimStart('.').TrimEnd('.'); if (string.IsNullOrEmpty(subDir)) { continue; } subDir = rootDir + "." + subDir; string projPath = Path.Combine(saveDir, subDir + "\\" + subDir + ".csproj"); bool isExist = false; for (int k = 0; k < existProjs.Count; k++) { if (existProjs[k].FileName.Equals(projPath, StringComparison.CurrentCultureIgnoreCase)) { isExist = true; break; } } if (isExist == false) { if (File.Exists(projPath)) { DialogResult rlt = MsgBox.ShowOkCancel("项目保存位置下已经存在:" + subDir + ",是否需要加载?"); if (rlt == DialogResult.OK) { sol3.AddFromFile(projPath, false); } continue; } string templatePath = sol3.GetProjectTemplate("ClassLibrary.zip", "CSharp"); Project proj = sol3.AddFromTemplate(templatePath, Path.Combine(saveDir, subDir), subDir, true); } else { MsgBox.ShowTip(subDir + "已经存在"); } } this.DialogResult = System.Windows.Forms.DialogResult.OK; } catch (Exception ex) { MsgBox.ShowTip(ex.Message); } finally { this.Cursor = Cursors.Default; } }
public static void Main(String[] args) { int n = 15; Solution3.FizzBuzz(n); }
public void SolutionThree_VerifyDeliveryFeesAndDiscounts() { Solution3 sol3 = new Solution3(); List <Article> articles = new List <Article>(); articles.Add(new Article(1, "Water", 100)); //80 articles.Add(new Article(2, "Cup", 200)); //180 List <Cart> carts = new List <Cart>(); List <CartItem> items1 = new List <CartItem>(); items1.Add(new CartItem(1, 3)); items1.Add(new CartItem(2, 1)); List <CartItem> items2 = new List <CartItem>(); items2.Add(new CartItem(1, 4)); items2.Add(new CartItem(2, 3)); List <CartItem> items3 = new List <CartItem>(); items3.Add(new CartItem(1, 0)); items3.Add(new CartItem(2, 10)); List <CartItem> items4 = new List <CartItem>(); items4.Add(new CartItem(1, 0)); int cart1_id = 1; int cart2_id = 2; int cart3_id = 3; int cart4_id = 4; carts.Add(new Cart(cart1_id, items1)); carts.Add(new Cart(cart2_id, items2)); carts.Add(new Cart(cart3_id, items3)); carts.Add(new Cart(cart4_id, items4)); List <DeliveryFee> delivery_fees = new List <DeliveryFee>(); int delivery_price1 = 1000; int delivery_price2 = 500; int delivery_price3 = 0; delivery_fees.Add(new DeliveryFee(new TransactionVolume(0, 1000), delivery_price1)); delivery_fees.Add(new DeliveryFee(new TransactionVolume(1000, 2000), delivery_price2)); delivery_fees.Add(new DeliveryFee(new TransactionVolume(2000, null), delivery_price3)); List <Discount> discounts = new List <Discount>(); discounts.Add(new Discount(1, "amount", 20)); discounts.Add(new Discount(2, "percentage", 10)); sol3.input = new JsonInputObject(articles, carts, delivery_fees, discounts); sol3.run(); int cart1_sub_total_expected = 420; int cart2_sub_total_expected = 860; int cart3_sub_total_expected = 1800; int cart4_sub_total_expected = 0; Assert.AreEqual(sol3.input.carts.Find(x => x.id == cart1_id).sub_total, cart1_sub_total_expected); Assert.AreEqual(sol3.input.carts.Find(x => x.id == cart2_id).sub_total, cart2_sub_total_expected); Assert.AreEqual(sol3.input.carts.Find(x => x.id == cart3_id).sub_total, cart3_sub_total_expected); Assert.AreEqual(sol3.input.carts.Find(x => x.id == cart4_id).sub_total, cart4_sub_total_expected); JsonOutputObject result = sol3.output; int cart1_total_expected = 1420; int cart2_total_expected = 1860; int cart3_total_expected = 2300; int cart4_total_expected = 1000; Assert.AreEqual(result.carts.Find(x => x.id == cart1_id).total, cart1_total_expected); Assert.AreEqual(result.carts.Find(x => x.id == cart2_id).total, cart2_total_expected); Assert.AreEqual(result.carts.Find(x => x.id == cart3_id).total, cart3_total_expected); Assert.AreEqual(result.carts.Find(x => x.id == cart4_id).total, cart4_total_expected); }
static void Main(string[] args) { #region Q5 string q51 = new Solution5().LongestPalindrome("babad"); Console.WriteLine(q51); string q52 = new Solution5().LongestPalindrome("cbbd"); Console.WriteLine(q52); string q53 = new Solution5().LongestPalindrome("ccd"); Console.WriteLine(q53); string q54 = new Solution5().LongestPalindrome("aacdefcaa"); Console.WriteLine(q54); string q55 = new Solution5().LongestPalindrome("a"); Console.WriteLine(q55); string q56 = new Solution5().LongestPalindrome("aa"); Console.WriteLine(q56); string q57 = new Solution5().LongestPalindrome("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); Console.WriteLine(q57); #endregion #region Q4 var q41 = new Solution4().FindMedianSortedArrays(new[] { 1, 3 }, new[] { 2 }); Console.WriteLine("OK"); var q42 = new Solution4().FindMedianSortedArrays(new[] { 1, 3 }, new[] { 2, 4 }); Console.WriteLine("OK"); #endregion #region Q3 var q30 = new Solution3().LengthOfLongestSubstring("abcabcbb"); Console.WriteLine(q30); var q31 = new Solution3().LengthOfLongestSubstring("bbbbb"); Console.WriteLine(q31); var q32 = new Solution3().LengthOfLongestSubstring("pwwkew"); Console.WriteLine(q32); var q33 = new Solution3().LengthOfLongestSubstring("jlygy"); Console.WriteLine(q33); #endregion #region Q2 var x = new Solution2.ListNode(2) { next = new Solution2.ListNode(4) { next = new Solution2.ListNode(3) } }; var y = new Solution2.ListNode(5) { next = new Solution2.ListNode(6) { next = new Solution2.ListNode(4) } }; var x1 = new Solution2.ListNode(9); var y1 = new Solution2.ListNode(1) { next = new Solution2.ListNode(9) { next = new Solution2.ListNode(9) } }; var q2 = new Solution2().AddTwoNumbers(x1, y1); Console.Write("ok"); #endregion #region Q1 var q1 = new Solution1().TwoSum(new[] { 5, 75, 25 }, 100); Console.WriteLine(q1); #endregion }