Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //75
- namespace PageCalculator
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] input = Console.ReadLine().
- Split(new[] { ' ', ',' },
- StringSplitOptions.RemoveEmptyEntries);
- int wordsPerPage = int.Parse(Console.ReadLine());
- string keyWord = Console.ReadLine();
- string[,] matrix = FillMatrix(input, wordsPerPage);
- int page = IsPresent(matrix, keyWord);
- Console.WriteLine(page);
- }
- public static string[,] FillMatrix(string[] tokens, int words)
- {
- string[,] matrix = new string[tokens.Length / words, words];
- int iterator = 0;
- for (int row = 0; row < matrix.GetLength(0); row++)
- {
- for (int col = 0; col < matrix.GetLength(1); col++)
- {
- matrix[row, col] = tokens[iterator++];
- }
- }
- return matrix;
- }
- public static int IsPresent(string[,] arr, string word)
- {
- bool isPresent = false;
- int index = 0;
- for (int row = 0; row < arr.GetLength(0); row++)
- {
- for (int col = 0; col < arr.GetLength(1); col++)
- {
- string w = arr[row, col];
- if (w == word)
- {
- isPresent = true;
- index = row;
- }
- }
- }
- if (isPresent)
- {
- return index + 1;
- }
- else
- {
- return -1;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement