Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 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 Greater
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             List<string> words = new List<string>();
  15.             words.Add("hi");
  16.             words.Add("from");
  17.             words.Add("from");
  18.             words.Add("this");
  19.             words.Add("world");
  20.  
  21.             Console.WriteLine(checkGreater(words, "world"));
  22.             Console.ReadLine();
  23.         }
  24.  
  25.         public static int checkGreater(List<string> a, string s)
  26.         {
  27.             int i = 0;
  28.             int count = 0;
  29.             int positionalValue = 0;
  30.             List<string> afterWords = new List<string>();
  31.             foreach (string word in a)
  32.             {
  33.                 if (word == s)
  34.                 {
  35.                     if (count == 0)
  36.                     {
  37.                         positionalValue = i;
  38.                         count++;
  39.                     }
  40.                 }
  41.  
  42.                 if (positionalValue != 0 && i > positionalValue)
  43.                 {
  44.                     if (word != s)
  45.                     {
  46.                         afterWords.Add(word);
  47.                     }
  48.                 }
  49.                 i++;
  50.             }
  51.             return afterWords.Count();
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement