Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.35 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 ConsoleApplication3
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var keyword = Console.ReadLine();
  14.             var lines = int.Parse(Console.ReadLine());
  15.  
  16.             var builder = new StringBuilder();
  17.             var text = Enumerable.Range(0, lines).Select(x => builder.Append(Console.ReadLine())).Last().ToString();
  18.  
  19.             var peshoPos = text.IndexOf(keyword);
  20.  
  21.             var dot = text.IndexOf('.', peshoPos);
  22.             var questions = text.IndexOf('?', peshoPos);
  23.  
  24.             var end = Math.Min(dot == -1 ? int.MaxValue : dot, questions == -1 ? int.MaxValue : questions);
  25.  
  26.             string substring = null; // we
  27.  
  28.             if (text[end] == '.')
  29.             {
  30.                 var start = Math.Max(text.LastIndexOf('.', peshoPos), text.LastIndexOf('?', peshoPos)) + 1;
  31.  
  32.                 substring = text.Substring(start, peshoPos - start);
  33.             }
  34.             else
  35.             {
  36.                 var start = text.IndexOfAny(" .?".ToCharArray(), peshoPos);
  37.  
  38.                 substring = text.Substring(start, end - start);
  39.             }
  40.  
  41.             Console.WriteLine(substring.Where(x => x != ' ').Sum(x => char.ToUpper(x)));
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement