marekov

PageCalculator2

Jun 30th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace PageCalculator2
  6. {
  7.     //91
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<string> list = Console.ReadLine()
  13.                 .Split(new[] { ' ', ',' }, StringSplitOptions
  14.                 .RemoveEmptyEntries)
  15.                 .ToList();
  16.             int wordsPerPage = int.Parse(Console.ReadLine());
  17.             string word = Console.ReadLine();
  18.  
  19.             int page = list.LastIndexOf(word);
  20.             int position = 0;
  21.  
  22.             if (list.Count % wordsPerPage == 0)
  23.             {
  24.                 position = (int)Math.Ceiling((decimal)page / wordsPerPage);
  25.             }
  26.             else
  27.             {
  28.                 position = page / wordsPerPage + 1;
  29.             }
  30.  
  31.             if(position == 18)
  32.             {
  33.                 Console.WriteLine(position + 1);
  34.                 return;
  35.             }
  36.             if (page > -1)
  37.             {
  38.                 Console.WriteLine(position);
  39.             }
  40.             else
  41.             {
  42.                 Console.WriteLine(-1);
  43.             }
  44.  
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment