|
1 | | -package JAVA; |
2 | | -import java.io.*; |
3 | | -import java.util.*; |
4 | | -import java.text.*; |
5 | | -import java.math.*; |
6 | | -import java.util.regex.*; |
7 | | - |
8 | | -public class DocsWithOddPagesByAssId { |
9 | | - public static void main(String args[] ) throws Exception { |
10 | | - /* Enter your code here. Read input from STDIN. Print output to STDOUT */ |
11 | | - Scanner sc = new Scanner(System.in); |
12 | | - Document[] doc = new Document[4]; |
13 | | - for(int i =0; i<4; i++) |
14 | | - { |
15 | | - int a = sc.nextInt();sc.nextLine(); |
16 | | - String b = sc.nextLine(); |
17 | | - String c = sc.nextLine(); |
18 | | - int d = sc.nextInt(); |
19 | | - |
20 | | - doc[i] = new Document(a,b,c,d); |
21 | | - } |
22 | | - Document[] d = docWithOddPages(doc); |
23 | | - if(d==null) |
24 | | - { |
25 | | - System.out.println("All pages are even"); |
26 | | - } |
27 | | - else |
28 | | - { |
29 | | - for(int i =0; i<d.length; i++) |
30 | | - { |
31 | | - System.out.println(d[i].getId()+" "+d[i].getTitle()+" "+d[i].getFolderName()+" "+d[i].getPages()); |
32 | | - } |
33 | | - } |
34 | | - |
35 | | - } |
36 | | - public static Document[] docWithOddPages(Document[] d) |
37 | | - { |
38 | | - Document[] st = new Document[0]; |
39 | | - for(int i=0; i<d.length; i++) |
40 | | - { |
41 | | - if(d[i].pages%2!=0) |
42 | | - { |
43 | | - st = Arrays.copyOf(st,st.length+1); |
44 | | - st[st.length-1]=d[i]; |
45 | | - } |
46 | | - } |
47 | | - for(int i =0; i<st.length; i++) |
48 | | - { |
49 | | - for(int j=i+1; j<st.length; j++) |
50 | | - { |
51 | | - if(st[i].getId()>st[j].getId()) |
52 | | - { |
53 | | - Document k=st[i]; |
54 | | - st[i]=st[j]; |
55 | | - st[j]=k; |
56 | | - } |
57 | | - } |
58 | | - } |
59 | | - if(st.length>0) |
60 | | - { |
61 | | - return st; |
62 | | - } |
63 | | - else |
64 | | - { |
65 | | - return null; |
66 | | - } |
67 | | - } |
68 | | -} |
69 | | -class Document |
70 | | -{ |
71 | | - int id; |
72 | | - String title; |
73 | | - String folderName; |
74 | | - int pages; |
75 | | - |
76 | | - public Document(int id, String title, String folderName, int pages) |
77 | | - { |
78 | | - this.id = id; |
79 | | - this.title = title; |
80 | | - this.folderName = folderName; |
81 | | - this.pages = pages; |
82 | | - } |
83 | | - |
84 | | - public int getId() |
85 | | - { |
86 | | - return id; |
87 | | - } |
88 | | - public void setId(int id) |
89 | | - { |
90 | | - this.id = id; |
91 | | - } |
92 | | - public String getTitle() |
93 | | - { |
94 | | - return title; |
95 | | - } |
96 | | - public void setTitle(String title) |
97 | | - { |
98 | | - this.title = title; |
99 | | - } |
100 | | - public String getFolderName() |
101 | | - { |
102 | | - return folderName; |
103 | | - } |
104 | | - public void setFolderName(String folderName) |
105 | | - { |
106 | | - this.folderName = folderName; |
107 | | - } |
108 | | - public int getPages() |
109 | | - { |
110 | | - return pages; |
111 | | - } |
112 | | - public void setPages(int pages) |
113 | | - { |
114 | | - this.pages = pages; |
115 | | - } |
116 | | -} |
| 1 | + |
| 2 | +import java.io.*; |
| 3 | +import java.util.*; |
| 4 | +import java.text.*; |
| 5 | +import java.math.*; |
| 6 | +import java.util.regex.*; |
| 7 | + |
| 8 | +public class DocsWithOddPagesByAssId { |
| 9 | + public static void main(String args[] ) throws Exception { |
| 10 | + /* Enter your code here. Read input from STDIN. Print output to STDOUT */ |
| 11 | + Scanner sc = new Scanner(System.in); |
| 12 | + Document[] doc = new Document[4]; |
| 13 | + for(int i =0; i<4; i++) |
| 14 | + { |
| 15 | + int a = sc.nextInt();sc.nextLine(); |
| 16 | + String b = sc.nextLine(); |
| 17 | + String c = sc.nextLine(); |
| 18 | + int d = sc.nextInt(); |
| 19 | + |
| 20 | + doc[i] = new Document(a,b,c,d); |
| 21 | + } |
| 22 | + Document[] d = docWithOddPages(doc); |
| 23 | + if(d==null) |
| 24 | + { |
| 25 | + System.out.println("All pages are even"); |
| 26 | + } |
| 27 | + else |
| 28 | + { |
| 29 | + for(int i =0; i<d.length; i++) |
| 30 | + { |
| 31 | + System.out.println(d[i].getId()+" "+d[i].getTitle()+" "+d[i].getFolderName()+" "+d[i].getPages()); |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + } |
| 36 | + public static Document[] docWithOddPages(Document[] d) |
| 37 | + { |
| 38 | + Document[] st = new Document[0]; |
| 39 | + for(int i=0; i<d.length; i++) |
| 40 | + { |
| 41 | + if(d[i].pages%2!=0) |
| 42 | + { |
| 43 | + st = Arrays.copyOf(st,st.length+1); |
| 44 | + st[st.length-1]=d[i]; |
| 45 | + } |
| 46 | + } |
| 47 | + for(int i =0; i<st.length; i++) |
| 48 | + { |
| 49 | + for(int j=i+1; j<st.length; j++) |
| 50 | + { |
| 51 | + if(st[i].getId()>st[j].getId()) |
| 52 | + { |
| 53 | + Document k=st[i]; |
| 54 | + st[i]=st[j]; |
| 55 | + st[j]=k; |
| 56 | + } |
| 57 | + } |
| 58 | + } |
| 59 | + if(st.length>0) |
| 60 | + { |
| 61 | + return st; |
| 62 | + } |
| 63 | + else |
| 64 | + { |
| 65 | + return null; |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +class Document |
| 70 | +{ |
| 71 | + int id; |
| 72 | + String title; |
| 73 | + String folderName; |
| 74 | + int pages; |
| 75 | + |
| 76 | + public Document(int id, String title, String folderName, int pages) |
| 77 | + { |
| 78 | + this.id = id; |
| 79 | + this.title = title; |
| 80 | + this.folderName = folderName; |
| 81 | + this.pages = pages; |
| 82 | + } |
| 83 | + |
| 84 | + public int getId() |
| 85 | + { |
| 86 | + return id; |
| 87 | + } |
| 88 | + public void setId(int id) |
| 89 | + { |
| 90 | + this.id = id; |
| 91 | + } |
| 92 | + public String getTitle() |
| 93 | + { |
| 94 | + return title; |
| 95 | + } |
| 96 | + public void setTitle(String title) |
| 97 | + { |
| 98 | + this.title = title; |
| 99 | + } |
| 100 | + public String getFolderName() |
| 101 | + { |
| 102 | + return folderName; |
| 103 | + } |
| 104 | + public void setFolderName(String folderName) |
| 105 | + { |
| 106 | + this.folderName = folderName; |
| 107 | + } |
| 108 | + public int getPages() |
| 109 | + { |
| 110 | + return pages; |
| 111 | + } |
| 112 | + public void setPages(int pages) |
| 113 | + { |
| 114 | + this.pages = pages; |
| 115 | + } |
| 116 | +} |
0 commit comments