Return to Snippet

Revision: 63628
at May 23, 2013 05:41 by smiklakhani


Updated Code
using System;
using System.Text.RegularExpressions;

class MyClass {
    public void search_query(string[] query, string[] pages) {
        // Write your code here.
        string tokensPattern =
            string.Format(".*{0}.*", string.Join(".*", query));
        
        if(query.Length > 0)
        {
            int pageCount = 0;
            
            foreach(string page in pages)
            {                
                Match match = Regex.Match(page, tokensPattern);
                
                if(match.Success)
                    pageCount++;
            }
            
            Console.WriteLine(pageCount.ToString());
        }
    }
}

Revision: 63627
at May 23, 2013 05:28 by smiklakhani


Initial Code
using System;
using System.Text.RegularExpressions;

class MyClass {
    public void search_query(string[] query, string[] pages) {
        // Write your code here.
        string tokensPattern =
            string.Format(".*{0}.*", string.Join(".*", query));
        
        Console.WriteLine(tokensPattern);
        
        if(query.Length > 0)
        {
            int pageCount = 0;
            
            foreach(string page in pages)
            {                
                Match match = Regex.Match(page, tokensPattern);
                
                if(match.Success)
                    pageCount++;
            }
            
            Console.WriteLine(pageCount.ToString());
        }
    }
}

Initial URL

                                

Initial Description
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.

Initial Title
Basic Search Query in C#

Initial Tags

                                

Initial Language
C#