on
thecodecandy
- Get link
- X
- Other Apps
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class
Solution {
final static Scanner sc = new Scanner(System.in);
public static void main(String args[] ) throws Exception {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
ArrayList<Document> obj = new ArrayList<>();
int id;
String title;
String folderName;
int pages;
do{
id =sc.nextInt();
sc.nextLine();
title = sc.nextLine();
folderName = sc.nextLine();
pages =sc.nextInt();
obj.add(new Document(id, title, folderName, pages));
}while(sc.hasNext());
//
ArrayList<Document> docsWithOddPages = docsWithOddPages(obj);
Collections.sort(docsWithOddPages, new Comparator<Document>(){
public int compare(Document o1, Document o2)
{
return Integer.compare(o1.getId(), o2.getId());
}
});
for(int i= 0; i < docsWithOddPages.size() ;i++){
System.out.println(docsWithOddPages.get(i).getId() + " " + docsWithOddPages.get(i).getTitle() + " " + docsWithOddPages.get(i).getFolderName() + " " + docsWithOddPages.get(i).getPages());
}
}
static ArrayList<Document> docsWithOddPages(ArrayList<Document> obj){
ArrayList<Document> oddPageDocuments = new ArrayList<>();
int k =0;
for(int i=0; i< obj.size(); i++){
if(obj.get(i).getPages() % 2 !=0){
oddPageDocuments.add(obj.get(i));
k++;
}
}
return oddPageDocuments;
}
}
class Document
{
private int id;
private String title;
private String folderName;
private int pages;
public Document(int id, String title, String folderName, int pages){
this.id = id;
this.title = title;
this.folderName = folderName;
this.pages= pages;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getFolderName() {
return folderName;
}
public void setFolderName(String folderName) {
this.folderName = folderName;
}
public int getPages() {
return pages;
}
public void setPages(int pages) {
this.pages = pages;
}
}
Comments
Post a Comment