NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.*;

public class Main {

private ArrayList<Photo> data;
private ArrayList<Slide> vert, hori, all;
private long N = 0, inter = 0;
private String INPUT_FILE = "e.txt", OUTPUT_FILE = "eres.txt";

public static void main(String[] args) {
Main ob = new Main();
ob.readFile();
ob.divideFunction();
ob.unionSlides();
ob.makeSlideShow();
}

private void readFile() {
try {
data = new ArrayList<>();
int ID = 0;
File file = new File(INPUT_FILE);
Scanner sc = new Scanner(file);
N = Long.valueOf(sc.nextLine());
while (sc.hasNextLine()) {
String line = sc.nextLine();
StringTokenizer tokenizer = new StringTokenizer(line, " ");
Photo obj = new Photo();
obj.setId(ID++);
obj.setOr(tokenizer.nextToken());
obj.setSize(Integer.parseInt(tokenizer.nextToken()));
ArrayList<String> tags = new ArrayList<>();
for (int i = 0; i < obj.getSize(); i++)
tags.add(tokenizer.nextToken());
obj.setTag(tags);
data.add(obj);
}

} catch (Exception e) {
System.out.print("Error: " + e.toString());
}
}

private void divideFunction() {
hori = new ArrayList<>();
vert = new ArrayList<>();
int count = 0, p1 = -1, p2 = -1;
for (Photo line : data) {
if (line.getOr().equals("H")) {
hori.add(new Slide(String.valueOf(line.getId()), new HashSet<String>(line.getTag()), line.getSize()));
} else {
count++;
if (count == 1)
p1 = line.getId();
if (count == 2) {
makeVerticalSlide(p1, line.getId());
count = 0;
}
}
}
}

private void makeVerticalSlide(int photoID1, int photoID2) {

Photo p1 = data.get(photoID1), p2 = data.get(photoID2);
Set<String> tags = unionTags(p1.getTag(), p2.getTag());
String ID = p1.getId() + " " + p2.getId();
vert.add(new Slide(ID, tags, tags.size()));

/*
ArrayList<Integer> rejected = new ArrayList<>();
Set<String> minSet = new HashSet<>();

for (int i = 0; i < V.size() - 1; i++) {
if (!rejected.contains(i)) {
System.out.println("Preni");
Photo iV = data.get(V.get(i));
int count = 201;
int a = -1, b = -1;
for (int j = i + 1; j < V.size(); j++) {
if (!rejected.contains(j)) {
Photo jV = data.get(V.get(j));
Set<String> tagsUnion = new HashSet<>(iV.getTag());
tagsUnion.addAll(jV.getTag());
System.out.println("Pri");
if (tagsUnion.size() < count) {
count = tagsUnion.size();
a = i;
b = j;
minSet = tagsUnion;
}
}
}
if (a != -1) {
vert.add(new Slide(a + " " + b, minSet, minSet.size()));
System.out.println(a+"t"+b);
rejected.add(a);
rejected.add(b);
}
}
}*/
}

private Set<String> unionTags(ArrayList<String> tag, ArrayList<String> tag1) {
Set<String> set = new HashSet<>();
set.addAll(tag);
set.addAll(tag1);
return set;
}

private void unionSlides() {
all = new ArrayList<>();
all.addAll(vert);
all.addAll(hori);
}

private void makeSlideShow() {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(OUTPUT_FILE, true));
int S = all.size();
writer.append(String.valueOf(S)).append("n");
for (Slide slide : all)
writer.append(slide.getID()).append("n");
writer.close();
} catch (Exception e) {
System.out.println("Error");
}
}

}

class Photo {
private String or;
private ArrayList<String> tag;
private int id, size;

Photo() {
}

public Photo(ArrayList<String> tag, String or, int id, int size) {
this.tag = tag;
this.or = or;
this.id = id;
this.size = size;
}

public ArrayList<String> getTag() {
return tag;
}

public void setTag(ArrayList<String> tag) {
this.tag = tag;
}

public String getOr() {
return or;
}

public void setOr(String or) {
this.or = or;
}

public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

public int getSize() {
return size;
}

public void setSize(int size) {
this.size = size;
}
}

class Slide {
private String ID;
private Set<String> tags;
private int count;

Slide(String ID, Set<String> tags, int count) {
this.ID = ID;
this.tags = tags;
this.count = count;
}

public Slide() {
}

public String getID() {
return ID;
}

public void setID(String ID) {
this.ID = ID;
}

public Set<String> getTags() {
return tags;
}

public void setTags(Set<String> tags) {
this.tags = tags;
}

public int getCount() {
return count;
}

public void setCount(int count) {
this.count = count;
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.