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 ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- String zbior = "AaBbMmKk";
- String wprowadzono = Console.ReadLine();
- Console.WriteLine(countOccurences(zbior,wprowadzono));
- Console.WriteLine(meanOfWordLength(wprowadzono));
- foreach ( String word in getWordsThatEndsWith(wprowadzono, ':', "ka")){
- Console.WriteLine(word);
- }
- Console.WriteLine(center(wprowadzono));
- Console.WriteLine(addSpacesAfterSeparators(wprowadzono)v);
- }
- static int countOccurences(String zbior, String input)
- {
- int iloscWystapien = 0;
- foreach (char c in zbior)
- {
- foreach (char c2 in input)
- if (c == c2)
- iloscWystapien++;
- }
- return iloscWystapien;
- }
- static int meanOfWordLength(String input)
- {
- int mean = 0;
- String[] words = input.Split(' ');
- foreach (String word in words)
- {
- mean += word.Length;
- }
- return mean/words.Length;
- }
- static List<String> getWordsThatEndsWith(String input, char separator, String sufix)
- {
- List<String> result = new List<String>();
- foreach (String word in input.Split(separator))
- {
- if (word.EndsWith(sufix))
- result.Add(word);
- }
- if (!result.Any())
- result.Add("Nie znaleziono");
- return result;
- }
- static String center(String input)
- {
- if (input.Length > 80)
- return input;
- return input.PadLeft(Console.WindowWidth / 2);
- }
- static String addSpacesAfterSeparators(String input)
- {
- input = input.Replace(". ", ".");
- input = input.Replace(", ", ",");
- input = input.Replace(".", ". ");
- input = input.Replace(",", ", ");
- return input;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement