Advertisement
n4wn4w

C# [HOMEWORK] - STRINGS

May 15th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.69 KB | None | 0 0
  1.  
  2.  
  3. uprajnenie v chas ///////////////
  4.  
  5.  
  6.  
  7.  string banList = Console.ReadLine();
  8.             string[] parts = Console.ReadLine().Split(new[] { '@' });
  9.             string username = parts[0]; // "hello"
  10.             string domain = parts[1]; // "example.com"
  11.      
  12.             string replace = new string('*', username.Length);
  13.             banList = banList.Replace(username, replace);
  14.            
  15.             Console.WriteLine(banList);
  16.  
  17. 1 zadacha   ///////////////////////////////////////////////////////////////////
  18.  
  19. string text = "Elrond: Cast it into the fire! Destroy it!";
  20.             char[] charr = text.ToCharArray();
  21.             Array.Reverse(charr);
  22.             Console.WriteLine(charr);
  23.  
  24.  
  25.  
  26. 2 zadacha ///////////////////////////////////////////////////////////////////////
  27.  
  28.  Console.Write("Enter a sequence of characters with max lenght 20: ");
  29.             string text = Console.ReadLine();
  30.             string result = text;
  31.  
  32.             if (text.Length <= 20)
  33.             {
  34.                 text = text.PadRight(20, '*');
  35.                 Console.WriteLine(text);
  36.             }
  37.             else
  38.             {
  39.                 result = text.Substring(0, 20);
  40.                 Console.WriteLine(result);
  41.             }
  42.  
  43.  
  44. 3 zadacha  ///////////////////////////////////////////////////////////////////////////////
  45.  
  46.  string text = Console.ReadLine().ToLower();
  47.             string search = Console.ReadLine().ToLower();
  48.  
  49.             int count = text.Select((c, i) => text.Substring(i)).Count(sub => sub.StartsWith(search));
  50.            
  51.             Console.WriteLine(count);
  52.  
  53.  
  54. 4 zadacha ////////////////////////////////////////////////////////////////////////////
  55.  
  56. string[] banList = Console.ReadLine().Split(',').Select(b => b.Trim()).ToArray();
  57.         string text = Console.ReadLine();
  58.         foreach (var ban in banList)
  59.         {
  60.             string replace = new string('*', ban.Length);
  61.             text = text.Replace(ban, replace);
  62.         }
  63.         Console.WriteLine(text);
  64.  
  65.  
  66. 5 zadacha /////////////////////////////////////////////////////////////////
  67.  
  68.  
  69. string input = Console.ReadLine();
  70.         foreach (var ch in input)
  71.         {
  72.             int num = Convert.ToInt32(ch);
  73.             Console.Write("\\u{0:x4}", num);
  74.         }
  75.         Console.WriteLine();
  76.  
  77.  
  78.  
  79. 6 zadacha //////////////////////////////////////////////////////////////////////
  80.  
  81. char[] symbols = { ',', '?', '!', '.', ' ' };
  82.         List<string> words = Console.ReadLine().Split(symbols, StringSplitOptions.RemoveEmptyEntries).Select(p => p).ToList();
  83.         var result = new SortedSet<string>();
  84.         bool isPalimandor = true;
  85.         foreach (string word in words)
  86.         {
  87.             isPalimandor = true;
  88.             if (word.Length == 1)
  89.             {
  90.                 result.Add(word);
  91.             }
  92.                ///////////////////////
  93.             for (int i = 0; i < word.Length / 2; i++)
  94.             {
  95.                 if (word[i] != word[word.Length - i - 1])
  96.                 {
  97.                     isPalimandor = false;
  98.                 }
  99.                 if (isPalimandor == true)
  100.                 {
  101.                    result.Add(word);
  102.                 }
  103.             }
  104.  
  105.            
  106.         }
  107.         Console.WriteLine(string.Join(", ", result));
  108.  
  109.  
  110. 7 zadacha  /////////////////////////////////////////////////////////////////////////////////////
  111.  
  112. Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
  113.             string[] input = Console.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  114.  
  115.             double sum = 0;
  116.             for (int i = 0; i < input.Length; i++)
  117.             {
  118.                 string fromInput = input[i];
  119.                 char before = fromInput[0];
  120.                 char after = fromInput[fromInput.Length - 1];
  121.                 double num = double.Parse(fromInput.Substring(1, fromInput.Length - 2));
  122.  
  123.                 if (char.IsUpper(before))
  124.                 {
  125.                     int beforePossition = before - 'A' + 1;
  126.                     num /= beforePossition;
  127.                 }
  128.                 else
  129.                 {
  130.                     int beforePossition = before - 'a' + 1;
  131.                     num *= beforePossition;
  132.                 }
  133.                 if (char.IsUpper(after))
  134.                 {
  135.                     int afrerPossition = after - 'A' + 1;
  136.                     num -= afrerPossition;
  137.                 }
  138.                 else
  139.                 {
  140.                     int afrerPossition = after - 'a' + 1;
  141.                     num += afrerPossition;
  142.                 }
  143.                 sum += num;
  144.             }
  145.             Console.WriteLine("{0:f2}", sum);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement