Skip to content

Commit ffe346d

Browse files
committed
initial commit
1 parent e3e99ac commit ffe346d

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

amcat-coding-ques/bomb.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 amcat;
7+
import java.util.*;
8+
/**
9+
*
10+
* @author yash verma
11+
*/
12+
public class bomb {
13+
static int[] bombDiff(int size, int key, int [] msg)
14+
{
15+
int sum;
16+
int result[]=new int[size];
17+
for(int i=0;i<size;i++)
18+
{
19+
sum=0;
20+
if(key>0)
21+
{
22+
for(int j=0;j<size;j++)
23+
{
24+
if(j==i)
25+
{ continue;}
26+
sum=sum+msg[j];
27+
}
28+
result[i]=sum;
29+
}
30+
else if(key<0)
31+
{
32+
sum=0;
33+
for(int j=0;j<i;j++)
34+
{
35+
sum=sum+msg[j];
36+
}
37+
result[i]=sum;
38+
}
39+
}
40+
return result;
41+
}
42+
public static void main(String[] args) {
43+
Scanner sc =new Scanner(System.in);
44+
int size=sc.nextInt();
45+
int key=sc.nextInt();
46+
int msg[]=new int[size];
47+
int c[]=new int[size];
48+
for(int i=0;i<size;i++)
49+
{
50+
msg[i]=sc.nextInt();
51+
}
52+
c=bombDiff(size,key,msg);
53+
for(int i=0;i<size;i++)
54+
{
55+
System.out.print(c[i]+" ");
56+
}
57+
}
58+
}

amcat-coding-ques/playing_cells2.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 playingcells;
7+
import java.util.*;
8+
/**
9+
*
10+
* @author yash verma
11+
*/
12+
public class java {
13+
static int[] colony(int cells[], int days) {
14+
for (int j = 0; j < days; j++)
15+
{
16+
int copy_cells[] = new int[10];
17+
for (int i = 1; i < 9; i++)
18+
{
19+
copy_cells[i] = cells[i - 1];
20+
}
21+
copy_cells[0] = 0;
22+
copy_cells[9] = 0;
23+
for (int i = 0; i < 8; i++)
24+
{
25+
cells[i] = copy_cells[i] == copy_cells[i + 2] ? 0 : 1;
26+
}
27+
}
28+
return cells;
29+
}
30+
public static void main(String[] args) {
31+
Scanner sc = new Scanner(System.in);
32+
int n = sc.nextInt();
33+
int a[] = new int[n];
34+
for (int i = 0; i < n; i++) {
35+
a[i] = sc.nextInt();
36+
}
37+
System.out.println("days");
38+
int d = sc.nextInt();
39+
a = colony(a, d);
40+
for (int i = 0; i < a.length; i++) {
41+
System.out.print(a[i] + " ");
42+
}
43+
}
44+
45+
}

0 commit comments

Comments
 (0)