Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CON9
- {
- class Program
- {
- static void Main(string[] args)
- {
- string s = "3 quick brown foxes jump ower 4 lazy dogs";
- Console.WriteLine(s);
- Console.WriteLine("SUM OF DIGITS: " + SumOfDigits(s));
- Console.WriteLine("LETTERCOUNT: " + CountLetters(s));
- Console.WriteLine("WORDCOUNT: " + CountWords(s));
- Console.WriteLine("\nPIG LATIN");
- Console.WriteLine(PigLatin(s));
- Console.WriteLine("\nASCII ");
- Console.WriteLine(String.Join(" ", GetASCII(s)));
- string e = Encrypt(s, 5);
- Console.WriteLine("\nENCRYPT WITH 5 ");
- Console.WriteLine(e);
- Console.WriteLine("\nENCRYPT WITH -5 ");
- Console.WriteLine(Encrypt(e, -5));
- //Console.WriteLine("\nREVERSE ");
- //Console.WriteLine(Reverse(s));
- Console.WriteLine("\nSORT ");
- Console.WriteLine(Sort(s));
- //Console.WriteLine("\nracecar is a palindrome " + IsPalindrome("racecar"));
- //Console.WriteLine("\nanagram is an anagram for magraan " + IsAnagram("anagram", "magraan"));
- Console.ReadLine();
- }
- static int SumOfDigits(string s)
- {
- string b = string.Empty;
- int a = 0;
- for (int i = 0; i < s.Length; i++)
- {
- if (char.IsDigit(s[i]))
- {
- b += s[i];
- a += Convert.ToInt32(b);
- b = String.Empty;
- }
- }
- return a;
- }
- static int CountLetters(string s)
- {
- string b = string.Empty;
- int a = 0;
- for (int i = 0; i < s.Length; i++)
- {
- if (char.IsLetter(s[i]))
- {
- a++;
- }
- }
- return a;
- }
- static int CountWords(string s)
- {
- int a = 1;
- for (int i = 0; i < s.Length; i++)
- {
- if (s[i] ==' ')
- {
- a++;
- }
- }
- return a;
- }
- static string PigLatin(string s)
- {
- string a = string.Empty;
- string temp = string.Empty;
- int getal1 = 0;
- int getal2 = 0;
- int getal3 = 0;
- int y = 0;
- string temp2 = string.Empty;
- int Lenght = 0;
- string reversestring = string.Empty;
- for (int i = 0; i < s.Length; i++)
- {
- if (s[i] == ' ')
- {
- getal1 = i;
- getal3 = getal1 - getal2;
- temp = s.Substring(getal2, getal3);
- getal2 = getal1;
- char firstCharacter;
- char[] vowels = { 'a', 'e', 'i', 'o', 'u' };
- int[] number = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
- if (char.IsDigit(temp[y]) || char.IsDigit(temp[1]))
- {
- temp = temp + " ";
- }
- else
- {
- firstCharacter = temp.ToLower().ToCharArray().ElementAt(1);
- for (int j = 0; j < 1; j++)
- {
- if (vowels.Contains(firstCharacter))
- {
- temp = temp + "way ";
- }
- else if (number.Contains(firstCharacter))
- {
- }
- else
- {
- Lenght = temp.Length - 1;
- while (Lenght >=0)
- {
- reversestring = reversestring + temp[Lenght];
- Lenght--;
- }
- temp = reversestring + "ay ";
- reversestring = "";
- }
- }
- }
- a += temp;
- }
- }
- return a;
- }
- static int[] GetASCII(string s)
- {
- int a = 0;
- int[] ascii = new int[s.Length];
- foreach (char c in s)
- {
- int unicode = c;
- ascii[a] = unicode;
- a++;
- }
- return ascii;
- }
- static string Encrypt(string s, int places)
- {
- string sys = string.Empty;
- foreach (char c in s)
- {
- int unicode = c + places;
- if (unicode >= 125)
- {
- unicode = unicode - 125;
- }
- char code = (char)unicode;
- sys += String.Format(Convert.ToString(code));
- }
- return sys;
- }
- static string Sort(string s)
- {
- string text = string.Empty;
- int temp = 0;
- int a = 0;
- int[] ascii = new int[s.Length];
- foreach (char c in s)
- {
- if (c != ' ')
- {
- int unicode = c;
- ascii[a] = c;
- a++;
- }
- else
- {
- }
- }
- for (int i = 0; i < ascii.Length; i++)
- {
- for (int j = 0; j < ascii.Length; j++)
- {
- if (ascii[i] < ascii[j])
- {
- temp = ascii[i];
- ascii[i] = ascii[j];
- ascii[j] = temp;
- }
- }
- }
- foreach (int i in ascii)
- {
- char number = (char)i;
- text += number;
- }
- return text;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement