Advertisement
Guest User

EX 9

a guest
Jan 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace CON9
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string s = "3 quick brown foxes jump ower 4 lazy dogs";
  14.             Console.WriteLine(s);
  15.             Console.WriteLine("SUM OF DIGITS: " + SumOfDigits(s));
  16.             Console.WriteLine("LETTERCOUNT: " + CountLetters(s));
  17.             Console.WriteLine("WORDCOUNT: " + CountWords(s));
  18.             Console.WriteLine("\nPIG LATIN");
  19.             Console.WriteLine(PigLatin(s));
  20.             Console.WriteLine("\nASCII ");
  21.             Console.WriteLine(String.Join(" ", GetASCII(s)));
  22.             string e = Encrypt(s, 5);
  23.             Console.WriteLine("\nENCRYPT WITH 5 ");
  24.             Console.WriteLine(e);
  25.             Console.WriteLine("\nENCRYPT WITH -5 ");
  26.             Console.WriteLine(Encrypt(e, -5));
  27.             //Console.WriteLine("\nREVERSE ");
  28.             //Console.WriteLine(Reverse(s));
  29.             Console.WriteLine("\nSORT ");
  30.             Console.WriteLine(Sort(s));
  31.             //Console.WriteLine("\nracecar is a palindrome " + IsPalindrome("racecar"));
  32.             //Console.WriteLine("\nanagram is an anagram for magraan " + IsAnagram("anagram", "magraan"));
  33.             Console.ReadLine();
  34.         }
  35.         static int SumOfDigits(string s)
  36.         {
  37.             string b = string.Empty;
  38.             int a = 0;
  39.             for (int i = 0; i < s.Length; i++)
  40.             {
  41.                 if (char.IsDigit(s[i]))
  42.                 {
  43.                     b += s[i];
  44.                     a += Convert.ToInt32(b);
  45.                     b = String.Empty;
  46.                 }
  47.             }  
  48.             return a;
  49.         }
  50.         static int CountLetters(string s)
  51.         {
  52.             string b = string.Empty;
  53.             int a = 0;
  54.             for (int i = 0; i < s.Length; i++)
  55.             {
  56.                 if (char.IsLetter(s[i]))
  57.                 {
  58.                     a++;  
  59.                 }
  60.             }
  61.             return a;
  62.         }
  63.         static int CountWords(string s)
  64.         {
  65.             int a = 1;
  66.             for (int i = 0; i < s.Length; i++)
  67.             {
  68.                 if (s[i] ==' ')
  69.                 {
  70.                     a++;
  71.                 }
  72.             }
  73.             return a;
  74.         }
  75.         static string PigLatin(string s)
  76.         {
  77.             string a = string.Empty;
  78.             string temp = string.Empty;
  79.             int getal1 = 0;
  80.             int getal2 = 0;
  81.             int getal3 = 0;
  82.             int y = 0;
  83.             string temp2 = string.Empty;
  84.             int Lenght = 0;
  85.             string reversestring = string.Empty;
  86.  
  87.             for (int i = 0; i < s.Length; i++)
  88.             {
  89.                
  90.                 if (s[i] == ' ')
  91.                 {
  92.                     getal1 = i;
  93.                     getal3 = getal1 - getal2;
  94.                     temp = s.Substring(getal2, getal3);
  95.                     getal2 = getal1;
  96.                     char firstCharacter;
  97.                     char[] vowels = { 'a', 'e', 'i', 'o', 'u' };
  98.                     int[] number = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
  99.                     if (char.IsDigit(temp[y]) || char.IsDigit(temp[1]))
  100.                     {
  101.                         temp = temp + " ";
  102.                        
  103.                     }
  104.                     else
  105.                     {
  106.                         firstCharacter = temp.ToLower().ToCharArray().ElementAt(1);
  107.                         for (int j = 0; j < 1; j++)
  108.                         {
  109.                             if (vowels.Contains(firstCharacter))
  110.                             {
  111.                                 temp = temp + "way ";
  112.                             }
  113.                             else if (number.Contains(firstCharacter))
  114.                             {
  115.                                
  116.                             }
  117.                             else
  118.                             {
  119.                                 Lenght = temp.Length - 1;
  120.                                 while (Lenght >=0)
  121.                                 {
  122.                                    
  123.                                     reversestring = reversestring + temp[Lenght];
  124.                                     Lenght--;
  125.                                 }
  126.  
  127.                                 temp = reversestring + "ay ";
  128.                                 reversestring = "";
  129.  
  130.                             }
  131.                         }
  132.                     }
  133.                     a += temp;
  134.                 }
  135.             }
  136.             return a;
  137.         }
  138.         static int[] GetASCII(string s)
  139.         {
  140.             int a = 0;
  141.             int[] ascii = new int[s.Length];
  142.             foreach (char c in s)
  143.             {
  144.                 int unicode = c;
  145.                 ascii[a] = unicode;
  146.                 a++;
  147.             }
  148.             return ascii;  
  149.         }
  150.         static string Encrypt(string s, int places)
  151.         {
  152.            
  153.             string sys = string.Empty;
  154.             foreach (char c in s)
  155.             {
  156.                 int unicode = c + places;
  157.                 if (unicode >= 125)
  158.                 {
  159.                     unicode = unicode - 125;
  160.                 }
  161.                 char code = (char)unicode;
  162.                 sys += String.Format(Convert.ToString(code));
  163.  
  164.             }
  165.             return sys;
  166.         }
  167.         static string Sort(string s)
  168.         {
  169.             string text = string.Empty;
  170.             int temp = 0;
  171.             int a = 0;
  172.             int[] ascii = new int[s.Length];
  173.             foreach (char c in s)
  174.             {
  175.                 if (c != ' ')
  176.                 {
  177.                     int unicode = c;
  178.                     ascii[a] = c;
  179.                     a++;
  180.                 }
  181.                 else
  182.                 {
  183.  
  184.                 }
  185.                
  186.             }
  187.             for (int i = 0; i < ascii.Length; i++)
  188.             {
  189.                 for (int j = 0; j < ascii.Length; j++)
  190.                 {
  191.                     if (ascii[i] < ascii[j])
  192.                     {
  193.                         temp = ascii[i];
  194.                         ascii[i] = ascii[j];
  195.                         ascii[j] = temp;
  196.                     }
  197.                 }
  198.             }
  199.             foreach (int i in ascii)
  200.             {
  201.                 char number = (char)i;
  202.                 text += number;
  203.             }
  204.             return text;
  205.         }
  206.     }
  207. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement