Untitled
unknown
plain_text
3 years ago
2.4 kB
7
Indexable
import java.io.File; import java.io.FileNotFoundException; import java.security.*; import java.util.*; public class Test{ public static void main(String[] args) throws NoSuchAlgorithmException { Queue<String> list = new LinkedList<>(); File myObj = new File("3.1.txt"); Scanner s = null; try { s = new Scanner(myObj); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } HashMap<String, Queue<String> > shashQueue = new HashMap<>(); while (s.hasNextLine()){ list.add(s.nextLine()); } Queue<String> shas = null; for (String input : list){ shas = new LinkedList<>(); shas.add(input); for (int i = 0; i < 80; i++){ shas.add(sha1(shas.peek())); System.out.println(shas.peek()); } shashQueue.put(input, shas); } HashMap<List, Integer> collnum = new HashMap<>(); //System.out.println("ciao"); for (String entry: shashQueue.keySet()){ for (String entry2 : shashQueue.keySet()){ List<String> coll = new ArrayList<>(); coll.add(entry); coll.add(entry2); if (entry.equals(entry2)) continue; for (String shaEntry : shashQueue.get(entry)){ for (String shaEntry2: shashQueue.get(entry2)){ if (shaEntry.equals(shaEntry2)){ collnum.put(coll, collnum.get(coll)+ 1); } } } } } System.out.println(collnum.size()); for (List singList: collnum.keySet()){ System.out.println(singList.get(0) + " " + singList.get(1) + " " + collnum.get(singList)); } } static String sha1(String input) throws NoSuchAlgorithmException { MessageDigest mDigest = MessageDigest.getInstance("SHA1"); byte[] result = mDigest.digest(input.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < result.length; i++) { sb.append(Integer.toString((result[i] & 0xff) + 0x100, 16).substring(1)); } return sb.toString(); } }
Editor is loading...