Professional Documents
Culture Documents
Algoritams Programing 1
Algoritams Programing 1
using System;
using System.Linq;
namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter your first word: ");
string word1 = Console.ReadLine();
Console.WriteLine(AnagaramChecker(word1, word2));
}
public static string AnagaramChecker(string word1, string word2)
{
string theyAre = "Those strings are anagrams!";
string theyAreNot = "Those strings are NOT anagrams!";
if (word1.Length != word2.Length)
{
return theyAreNot;
}
else
{
foreach (var x in word1)
{
int n = word2.IndexOf(x);
if (x == -1)
{
return theyAreNot;
}
word2 = word2.Remove(x, 1);
}
}
return theyAre;
}
}
}
reverse:
using System;
using System.Linq;
namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter a string: ");
string str = Console.ReadLine();
Console.WriteLine($"Reversed string is: {ReverseString(str)}");
}
public static string ReverseString(string str)
{
string result = null;
for (int i = str.Length - 1; i >= 0; i--)
{
result = result + str[i];
}
return result;
}
}
}
counting words:
using System;
using System.Linq;
namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter a string: ");
string str = Console.ReadLine();
Console.WriteLine($"Numkber of words ion string is:
{WordCounter(str)}");
}
public static int WordCounter(string str)
{
int result = 1;
return result;
}
}
}
Pallindrome:
using System;
using System.Linq;
namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter a string: ");
string str = Console.ReadLine();
Console.WriteLine($"Numkber of words ion string is:
{PallindromeChecker(str)}");
}
if (str.ToLower() == result.ToLower())
{
return itIs;
}
else
{
return itIsNot;
}
}
}
}
using System;
using System.Linq;
namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter a string: ");
string str = Console.ReadLine();
Console.WriteLine($"New string witout duplicates is:
{DuplicateRemover(str)}");
}
using System;
using System.Linq;
namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter a string: ");
string str = Console.ReadLine();
Console.WriteLine($"Highest occured character in string is:
{HighestChar(str)}");
}
unique string:
using System;
using System.Linq;
namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter a string: ");
string str = Console.ReadLine();
Console.WriteLine($"{UniqueStringChecker(str)}");
}
replace spaces:
using System;
using System.Linq;
namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter a string: ");
string str = Console.ReadLine();
Console.WriteLine($"{CharReplacer(str)}");
}
public static string CharReplacer(string str)
{
string result = str.Replace(' ', '%');
return result;
}
}
}
substrings of strings:
using System;
using System.Linq;
namespace Algorythams
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Please enter a string: ");
string str = Console.ReadLine();
SubstringString(str);
}
public static void SubstringString(string str)
{
for (int i = 1; i < str.Length; i++)
{
for (int j = 0; j < str.Length - i; j++)
{
string substring = str.Substring(j, i);
Console.WriteLine(substring);
}
}
}
}
}