Posted By

smiklakhani on 05/23/13


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

danfinrud55
Priestd09


Basic Search Query in C#


 / Published in: C#
 

Test 0: OK! Test 1: OK! Test 2: OK! Test 3: Error: your code didn't finish in less than 2 seconds. Test 4: Error: your code didn't finish in less than 2 seconds. Test 5: Error: your code didn't finish in less than 2 seconds.

  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. class MyClass {
  5. public void search_query(string[] query, string[] pages) {
  6. // Write your code here.
  7. string tokensPattern =
  8. string.Format(".*{0}.*", string.Join(".*", query));
  9.  
  10. if(query.Length > 0)
  11. {
  12. int pageCount = 0;
  13.  
  14. foreach(string page in pages)
  15. {
  16. Match match = Regex.Match(page, tokensPattern);
  17.  
  18. if(match.Success)
  19. pageCount++;
  20. }
  21.  
  22. Console.WriteLine(pageCount.ToString());
  23. }
  24. }
  25. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: smiklakhani on May 23, 2013

Test 0: OK! Test 1: OK! Test 2: OK! Test 3: Error: your code didn't finish in less than 2 seconds. Test 4: Error: your code didn't finish in less than 2 seconds. Test 5: Error: your code didn't finish in less than 2 seconds.

You need to login to post a comment.