Skip to content

Commit be14797

Browse files
SpreehaMadhavBahl
authored andcommitted
day 24 and 25 (#228)
1 parent 6669ac6 commit be14797

File tree

4 files changed

+256
-0
lines changed

4 files changed

+256
-0
lines changed

day24/Java/circularRotation.java

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package javaapplication3;
7+
8+
/**
9+
* @date 03/01/19
10+
* @author SPREEHA DUTTA
11+
*/
12+
import java.util.*;
13+
public class circularRotation {
14+
public static boolean circular(List a1,List a2)
15+
{
16+
int p;int c=0;int i,j=0;
17+
if(a1.size()!=a2.size())
18+
return false;
19+
else
20+
{
21+
p=a2.indexOf(a1.get(0));
22+
if(p!=-1)
23+
{
24+
for(i=p;i<a2.size();i++)
25+
{
26+
if(a2.get(i)==a1.get(j))
27+
{
28+
c++;
29+
j++;
30+
}
31+
else
32+
break;
33+
}
34+
for(i=0;i<p;i++)
35+
{
36+
if(a2.get(i)==a1.get(j))
37+
{
38+
c++; j++;
39+
}
40+
else
41+
break;
42+
}
43+
}
44+
if(c==a1.size())
45+
return true;
46+
else
47+
return false;
48+
}
49+
50+
}
51+
public static void main(String []args)
52+
{
53+
Scanner sc=new Scanner(System.in);
54+
int m,n,i;
55+
ArrayList<Integer> a = new ArrayList<Integer>();
56+
ArrayList<Integer> a2 = new ArrayList<Integer>();
57+
System.out.println("Enter size and insert elements into first array ");
58+
m=sc.nextInt();
59+
for(i=0;i<m;i++)
60+
a.add(sc.nextInt());
61+
System.out.println("Enter size and insert elements into second array ");
62+
n=sc.nextInt();
63+
for(i=0;i<n;i++)
64+
a2.add(sc.nextInt());
65+
boolean res = circular(a,a2);
66+
System.out.println(res);
67+
}
68+
}

day24/README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,72 @@ def main
104104
end
105105

106106
main
107+
```
108+
109+
## Java Implementation
110+
111+
### [Solution](./Java/circularRotation.java)
112+
113+
```java
114+
/**
115+
* @date 03/01/19
116+
* @author SPREEHA DUTTA
117+
*/
118+
import java.util.*;
119+
public class circularRotation {
120+
public static boolean circular(List a1,List a2)
121+
{
122+
int p;int c=0;int i,j=0;
123+
if(a1.size()!=a2.size())
124+
return false;
125+
else
126+
{
127+
p=a2.indexOf(a1.get(0));
128+
if(p!=-1)
129+
{
130+
for(i=p;i<a2.size();i++)
131+
{
132+
if(a2.get(i)==a1.get(j))
133+
{
134+
c++;
135+
j++;
136+
}
137+
else
138+
break;
139+
}
140+
for(i=0;i<p;i++)
141+
{
142+
if(a2.get(i)==a1.get(j))
143+
{
144+
c++; j++;
145+
}
146+
else
147+
break;
148+
}
149+
}
150+
if(c==a1.size())
151+
return true;
152+
else
153+
return false;
154+
}
155+
156+
}
157+
public static void main(String []args)
158+
{
159+
Scanner sc=new Scanner(System.in);
160+
int m,n,i;
161+
ArrayList<Integer> a = new ArrayList<Integer>();
162+
ArrayList<Integer> a2 = new ArrayList<Integer>();
163+
System.out.println("Enter size and insert elements into first array ");
164+
m=sc.nextInt();
165+
for(i=0;i<m;i++)
166+
a.add(sc.nextInt());
167+
System.out.println("Enter size and insert elements into second array ");
168+
n=sc.nextInt();
169+
for(i=0;i<n;i++)
170+
a2.add(sc.nextInt());
171+
boolean res = circular(a,a2);
172+
System.out.println(res);
173+
}
174+
}
107175
```

day25/Java/rotateTile.java

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package javaapplication3;
7+
8+
/**
9+
* @date 3/02/19
10+
* @author SPREEHA DUTTA
11+
*/
12+
import java.util.*;
13+
public class rotateTile {
14+
public static int[][] rotate(int arr[][])
15+
{
16+
int i,j,ri=0;
17+
int rj=arr.length-1;
18+
int rot[][]=new int[arr.length][arr.length];
19+
for(i=0;i<arr.length;i++)
20+
{
21+
for(j=0;j<arr.length;j++)
22+
{
23+
rot[ri][rj]=arr[i][j];
24+
ri++;
25+
}
26+
rj--; ri=0;
27+
}
28+
return rot;
29+
}
30+
public static void main(String []args)
31+
{
32+
int n,i,j;
33+
Scanner sc=new Scanner(System.in);
34+
n=sc.nextInt();
35+
int ri=0,rj=n-1;
36+
int arr[][]=new int[n][n];
37+
for(i=0;i<n;i++)
38+
for(j=0;j<n;j++)
39+
arr[i][j]=sc.nextInt();
40+
System.out.println("Original matrix is ");
41+
for(i=0;i<n;i++)
42+
{
43+
for(j=0;j<n;j++)
44+
{
45+
System.out.print(arr[i][j]+" ");
46+
}
47+
System.out.println();
48+
}
49+
int rot[][]=rotate(arr);
50+
System.out.println("Rotated matrix is ");
51+
for(i=0;i<n;i++)
52+
{
53+
for(j=0;j<n;j++)
54+
{
55+
System.out.print(rot[i][j]+" ");
56+
}
57+
System.out.println();
58+
}
59+
}
60+
}

day25/README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,64 @@ rotateTile ([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
9898

9999
```js
100100
To be added
101+
```
102+
103+
## Java Implementation
104+
105+
### [Solution](./Java/rotateTile.java)
106+
107+
```java
108+
/**
109+
* @date 3/02/19
110+
* @author SPREEHA DUTTA
111+
*/
112+
import java.util.*;
113+
public class rotateTile {
114+
public static int[][] rotate(int arr[][])
115+
{
116+
int i,j,ri=0;
117+
int rj=arr.length-1;
118+
int rot[][]=new int[arr.length][arr.length];
119+
for(i=0;i<arr.length;i++)
120+
{
121+
for(j=0;j<arr.length;j++)
122+
{
123+
rot[ri][rj]=arr[i][j];
124+
ri++;
125+
}
126+
rj--; ri=0;
127+
}
128+
return rot;
129+
}
130+
public static void main(String []args)
131+
{
132+
int n,i,j;
133+
Scanner sc=new Scanner(System.in);
134+
n=sc.nextInt();
135+
int ri=0,rj=n-1;
136+
int arr[][]=new int[n][n];
137+
for(i=0;i<n;i++)
138+
for(j=0;j<n;j++)
139+
arr[i][j]=sc.nextInt();
140+
System.out.println("Original matrix is ");
141+
for(i=0;i<n;i++)
142+
{
143+
for(j=0;j<n;j++)
144+
{
145+
System.out.print(arr[i][j]+" ");
146+
}
147+
System.out.println();
148+
}
149+
int rot[][]=rotate(arr);
150+
System.out.println("Rotated matrix is ");
151+
for(i=0;i<n;i++)
152+
{
153+
for(j=0;j<n;j++)
154+
{
155+
System.out.print(rot[i][j]+" ");
156+
}
157+
System.out.println();
158+
}
159+
}
160+
}
101161
```

0 commit comments

Comments
 (0)