using System.Collections.Generic;
using System.Globalization;
public static void Main()
Program p = new Program();
bool result = p.AreAnagrams("mamanp","namamg");
Console.WriteLine(result);
Program algo1 = new Program();
bool resultStringReversed = algo1.IsPalindromeReworked("bonjour");
Program algo2 = new Program();
string resultMerging = algo2.MergingStringReworked("tendrement", "alerte");
Program algo3 = new Program();
bool resultSubSequence = algo3.SubSequence("hlba", "BlahBlahBlah");
Program algo4 = new Program();
string resultTabIntersection = algo4.IntersectionTable([7, 2, 6, 2, 3, 4, 8, 9, 1, 2, 5, 6], [6, 7, 8, 4, 5, 8, 2, 1, 7, 6, 9]);
Program algo5 = new Program();
string resultMaxProfit = algo5.ProfitMax([2, 6, 9, 3, 8]);
Console.WriteLine(resultStringReversed);
Console.WriteLine(resultMerging);
Console.WriteLine(resultSubSequence);
Console.WriteLine(resultTabIntersection);
Console.WriteLine(resultMaxProfit);
public bool IsPalindromeReworked(string str)
string stringReversed = string.Empty;
char[] chars = str.ToCharArray();
for (int i = str.Length - 1; i>=0; i--)
stringReversed += chars[i];
if (str == stringReversed)
public string MergingStringReworked(string str1, string str2)
str1 = str1.ToLowerInvariant().Replace(" ", "");
str2 = str2.ToLowerInvariant().Replace(" ", "");
var sb = new StringBuilder();
for (int i = 0; i < str1.Length; i++)
if (str1.Length > str2.Length)
for (int i = IndexJ; i <str2.Length; i++)
else if (str2.Length > str1.Length)
for (int i = IndexJ; i < str2.Length; i++)
public bool SubSequence(string str1, string str2)
str1 = str1.ToLowerInvariant().Replace(" ", "");
str2 = str2.ToLowerInvariant().Replace(" ", "");
if (string.IsNullOrEmpty(str1) || string.IsNullOrEmpty(str2))
foreach (char c2 in str2)
if (i < str1.Length && c2 == str1[i])
public string IntersectionTable(int[] intTab1, int[] intTab2)
if (intTab1 == null || intTab2 == null)
throw new ArgumentNullException( "L'un des tableaux est null");
HashSet<int> ints = [.. intTab1];
HashSet<int> intTabFinal = new HashSet<int>();
foreach (var j in intTab2)
return "[" + string.Join(", ", intTabFinal) + "]";;
public string ProfitMax(int[] prices)
for (int i = 1; i < prices.Length; i++)
int potentialProfit = selling - buying;
if (potentialProfit > maxProfit)
maxProfit = potentialProfit;
if (selling < buying && i < prices.Length - 1)
return maxProfit.ToString();
private bool AreAnagrams(string str1, string str2)
if(str1.Length != str2.Length)
Dictionary<char,int> dict = new Dictionary<char, int>();
Dictionary<char,int> dict2 = new Dictionary<char,int>();
foreach (var keyValuePair in dict)
if(!dict2.ContainsKey(keyValuePair.Key) || !dict2.ContainsValue(keyValuePair.Value))
foreach (var keyValuePair in dict2)
if(!dict.ContainsKey(keyValuePair.Key) || !dict.ContainsValue(keyValuePair.Value))