Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. package com.company;
  2.  
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.File;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import java.util.Arrays;
  9. import java.util.Calendar;
  10.  
  11.  
  12.  
  13. public class Main {
  14. private static char[] word;
  15.  
  16. public static void main(String[] args) {
  17.  
  18.  
  19. load("slowo2.txt");
  20.  
  21.  
  22. long start_time = Calendar.getInstance().getTimeInMillis();
  23.  
  24. int found = 0;
  25. for (int i = 1; i < word.length / 2 + 1; i++) {
  26. if (Arrays.equals(word, 0, i - 1, word, i, i + i - 1)) found = i;
  27. //if (isEqual(i)) found = i;
  28. }
  29.  
  30. long stop_time = Calendar.getInstance().getTimeInMillis();
  31. System.out.println("Found: " + (found * 2) + " in " + (stop_time - start_time)/1000 + " s.");
  32. }
  33.  
  34.  
  35. // public static boolean isEqual(int to) {
  36. //
  37. // for (int i = 0; i < to; i++) {
  38. // if (word[i] != word[i + to]) {
  39. // return false;
  40. // }
  41. // }
  42. //
  43. // return true;
  44. // }
  45.  
  46. private static void load(String path) {
  47. File file = new File(path);
  48. word = new char[(int) file.length()];
  49. try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
  50. reader.read(word);
  51. } catch (IOException e) {
  52. e.printStackTrace();
  53. }
  54. }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement