Skip to content

Commit

Permalink
day 30 (#213)
Browse files Browse the repository at this point in the history
  • Loading branch information
Spreeha authored and MadhavBahl committed Feb 8, 2019
1 parent 79c2a9b commit 34a8adb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
33 changes: 33 additions & 0 deletions day30/Java/naive.java
@@ -0,0 +1,33 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication3;

/**
* @date 30/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class naive {
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
String s,p;int i,j;String str;int c=0;
s=sc.next();
System.out.println("Enter pattern ");
p=sc.next();
for(i=0;i<s.length()-p.length();i++)
{
str=s.substring(i,i+p.length());
if(str.equals(p))
{
System.out.println(i); c=1;
break;
}
}
if(c==0)
System.out.println("Pattern not found");
}
}
34 changes: 34 additions & 0 deletions day30/README.md
Expand Up @@ -28,6 +28,39 @@ output: 6 (start index of the found pattern)
to be added
```

## Java Implementation

### [Solution](./Java/naive.java)

```java
/**
* @date 30/01/19
* @author SPREEHA DUTTA
*/
import java.util.*;
public class naive {
public static void main(String []args)
{
Scanner sc=new Scanner(System.in);
String s,p;int i,j;String str;int c=0;
s=sc.next();
System.out.println("Enter pattern ");
p=sc.next();
for(i=0;i<s.length()-p.length();i++)
{
str=s.substring(i,i+p.length());
if(str.equals(p))
{
System.out.println(i); c=1;
break;
}
}
if(c==0)
System.out.println("Pattern not found");
}
}
```

### [C++ Implementation](./C++/naiveSearch.cpp)

```cpp
Expand Down Expand Up @@ -110,3 +143,4 @@ int main(){
return 0;
}
```

0 comments on commit 34a8adb

Please sign in to comment.