Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 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 ConsoleApplication1
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. String zbior = "AaBbMmKk";
  14. String wprowadzono = Console.ReadLine();
  15.  
  16. Console.WriteLine(countOccurences(zbior,wprowadzono));
  17. Console.WriteLine(meanOfWordLength(wprowadzono));
  18. foreach ( String word in getWordsThatEndsWith(wprowadzono, ':', "ka")){
  19. Console.WriteLine(word);
  20. }
  21.  
  22. Console.WriteLine(center(wprowadzono));
  23.  
  24. Console.WriteLine(addSpacesAfterSeparators(wprowadzono)v);
  25. }
  26.  
  27.  
  28. static int countOccurences(String zbior, String input)
  29. {
  30. int iloscWystapien = 0;
  31. foreach (char c in zbior)
  32. {
  33. foreach (char c2 in input)
  34. if (c == c2)
  35. iloscWystapien++;
  36. }
  37. return iloscWystapien;
  38. }
  39.  
  40. static int meanOfWordLength(String input)
  41. {
  42. int mean = 0;
  43. String[] words = input.Split(' ');
  44. foreach (String word in words)
  45. {
  46. mean += word.Length;
  47. }
  48. return mean/words.Length;
  49. }
  50.  
  51. static List<String> getWordsThatEndsWith(String input, char separator, String sufix)
  52. {
  53. List<String> result = new List<String>();
  54. foreach (String word in input.Split(separator))
  55. {
  56. if (word.EndsWith(sufix))
  57. result.Add(word);
  58. }
  59. if (!result.Any())
  60. result.Add("Nie znaleziono");
  61. return result;
  62. }
  63.  
  64. static String center(String input)
  65. {
  66. if (input.Length > 80)
  67. return input;
  68. return input.PadLeft(Console.WindowWidth / 2);
  69. }
  70.  
  71. static String addSpacesAfterSeparators(String input)
  72. {
  73. input = input.Replace(". ", ".");
  74. input = input.Replace(", ", ",");
  75.  
  76. input = input.Replace(".", ". ");
  77. input = input.Replace(",", ", ");
  78. return input;
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement