Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package s_est_la_examinie;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.io.ObjectInputStream.GetField;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.HashSet;
- import java.util.Iterator;
- import java.util.Map;
- import java.util.Set;
- public class C {
- private static final File fileIn = new File("input.txt");
- private static final File fileOut = new File("output.txt");
- private static HashMap<Key, HashSet<String>> map = new HashMap<Key, HashSet<String>>();
- public static void main(String[] args) throws IOException {
- long time = new Date().getTime();
- //
- run(args);
- //
- System.out.println("----------------------------");
- System.out.println(new Date().getTime() - time + " ms");
- }
- static void run(String[] args) throws IOException {
- System.out.println(fileIn.getAbsolutePath());
- BufferedReader in = new BufferedReader(new FileReader(fileIn));
- PrintWriter out = new PrintWriter(new FileWriter(fileOut));
- byte N = Byte.parseByte(in.readLine());
- String msg;
- int A,T,C,G;
- char a;
- for (int i = 0; i < N; i++) {
- msg = in.readLine();
- A = (int) msg.chars().filter(ch -> ch == 'A').count();
- T = (int) msg.chars().filter(ch -> ch == 'T').count();
- C = (int) msg.chars().filter(ch -> ch == 'C').count();
- G = (int) msg.chars().filter(ch -> ch == 'G').count();
- Key key = new Key(A, T, C, G);
- HashSet<String> list = map.get(key);
- if (list == null) {
- list = new HashSet<String>();
- map.put(key, list);
- }
- list.add(msg);
- }
- in.close();
- out.println(map.size());
- for (HashSet<String> list : map.values()) {
- Iterator<String> iter = list.iterator();
- while (iter.hasNext()) {
- out.print(iter.next());
- if (iter.hasNext()) out.print(" ");
- }
- out.println();
- }
- out.close();
- }
- }
- class Key {
- private int A, T, C, G;
- public Key(int A, int T, int C, int G) {
- this.A = A;
- this.T = T;
- this.C = C;
- this.G = G;
- }
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + A;
- result = prime * result + C;
- result = prime * result + G;
- result = prime * result + T;
- return result;
- }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Key other = (Key) obj;
- if (A != other.A)
- return false;
- if (C != other.C)
- return false;
- if (G != other.G)
- return false;
- if (T != other.T)
- return false;
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement