-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem.java
More file actions
87 lines (83 loc) · 1.7 KB
/
Problem.java
File metadata and controls
87 lines (83 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.Scanner;
public class Problem {
public static void main(String[] args) {
int[][] dogwalker;
int dog[],i,j=1,t=1,s=0;
System.out.println("enter the no. of dogwalkers");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
dogwalker = new int[n+1][2];
System.out.println("enter the no. of dogs");
int l = sc.nextInt();
dog = new int[l+1];
if(n>l){
System.out.println("no. of dogs are less than dogwalkers");
}
else if(n<l/2){
System.out.println("no. of dogs are more than twice of dogwalkers");
}
else{
for(i=1 ; i<=l;i++){
System.out.println("enter the weight of "+i+" dog:" );
dog[i] = sc.nextInt();
}
int a = 0;
if(n == l){
for(i=1;i<=n;i++){
dogwalker[i][0] = dog[i];
System.out.println(i+" dogwalker has dog of weight " +dogwalker[i][1]);
}
}
else if((2*n)==l){
for(i=1;i<=n;i++){
System.out.println("dogwalker " +i+ " have dogs \n");
for(j=0;j<=1;j++){
dogwalker[i][j] = dog[i+j+a];
System.out.println("\t dog "+ (j+1) + " weight "+dogwalker[i][j] );
}
a++;
}
}
else{
for(i=1;i<=n;i++){
if(j<=l){
dogwalker[i][0] = dog[j];
j=j+2;
}
else{
if(t==1){
if(l%2==0){
j=l;
t++;
s++;
}
else{
j=l+1;
t++;
}
}
if(j>1){
dogwalker[i][0] = dog[j];
j=j-2;
}
}
}
s=j;
j=2;
i=1;
while(j<=s){
dogwalker[i][1] = dog[j];
i++;
j=j+2;
}
for(i=1;i<=n;i++){
System.out.println("dogwalker " +i+ " have dogs \n");
for(j=0;j<=1;j++){
System.out.println("\t dog "+ (j+1) + " weight "+dogwalker[i][j] );
}
}
}
}
sc.close();
}
}