Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

Anagrams:

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("Enter your second word: ");


string word2 = 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;

for (int i = 0; i < str.Length; i++)


{
if (str[i] == ' ')
{
result++;
}
}

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)}");
}

public static string PallindromeChecker(string str)


{
string itIs = "Word is pallindrome!";
string itIsNot = "Word is NOT pallindrome!";

string result = null;

for (int i = str.Length - 1; i >= 0; i--)


{
result = result + str[i];
}

if (str.ToLower() == result.ToLower())
{
return itIs;
}
else
{
return itIsNot;
}
}

}
}

string witout duplicates:

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)}");
}

public static string DuplicateRemover(string str)


{
for (int i = 0; i < str.Length; i++)
{
for (int j = 1 + i; j < str.Length; j++)
{
if (str[i] == str[j])
{
str = str.Remove(j, 1);
}
}
}
return str;
}
}
}

Occured char in 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($"Highest occured character in string is:
{HighestChar(str)}");
}

public static char HighestChar(string str)


{
int[] arr = new int[256];

for (int i = 0; i < str.Length; i++)


{
arr[str[i]]++;
}

int max = -1;


char result = ' ';

for (int i = 0; i < str.Length; i++)


{
if (max < arr[str[i]])
{
max = arr[str[i]];
result = str[i];
}
}
return result;
}
}
}

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)}");
}

public static string UniqueStringChecker(string str)


{
string itIsUnique = "String you provided is unique!";
string itIsNotUnique = "String you provided is NOT unique!";

for (int i = 0; i < str.Length; i++)


{
for (int j = 1 + i; j < str.Length; j++)
{
if (str[i] == str[j])
{
return itIsNotUnique;
}
}
}
return itIsUnique;
}
}
}

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);
}
}
}
}
}

You might also like