Advertisement
Guest User

Untitled

a guest
Nov 26th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.*;
  5.  
  6.  
  7. public class Lozinki {
  8. public static void main (String[] args) throws IOException {
  9. BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  10. int N = Integer.parseInt(br.readLine());
  11. HashTable<User> hashTable = new HashTable<User>(2*N);
  12. for(int i=1;i<=N;i++){
  13. String imelozinka = br.readLine();
  14. String[] pom = imelozinka.split(" ");
  15. hashTable.insert(new User (pom[0], pom[1]));
  16. }
  17. String line = br.readLine();
  18. while(!line.equals("KRAJ")){
  19. String[] pom = line.split(" ");
  20. if(hashTable.find(new User (pom[0], pom[1]))){
  21. System.out.println("Najaven");
  22. break;
  23. }
  24. else
  25. System.out.println("Nenajaven");
  26. line = br.readLine();
  27. }
  28. br.close();
  29. }
  30. }
  31.  
  32. class User{
  33. String username;
  34. String password;
  35. public User(String _username, String _password){
  36. username = _username;
  37. password = _password;
  38. }
  39. public String getUsername(){
  40. return username;
  41. }
  42. public String getPassword(){
  43. return password;
  44. }
  45. public int hashCode(){
  46. return Math.abs(username.hashCode());
  47. }
  48. public String toString(){
  49. return username + " " + password;
  50. }
  51. public boolean equals(User other){
  52. if(other == null) return false;
  53. if(other == this) return true;
  54. if(other.username.equals(username) && other.password.equals(password))
  55. return true;
  56. return false;
  57. }
  58. }
  59.  
  60. class HashTable<E>{
  61. List<User> buckets [];
  62.  
  63. @SuppressWarnings("unchecked")
  64. public HashTable(int m){
  65. buckets = (ArrayList<User> []) new ArrayList[m];
  66. for(int i = 0; i < m; i++){
  67. buckets[i] = new ArrayList<User>();
  68. }
  69. }
  70. public void insert(User ins){
  71. int index = hash(ins);
  72. buckets[index].add(ins);
  73. }
  74. public int hash(User U){
  75. return U.hashCode()%buckets.length;
  76. }
  77. public boolean find(User entry){
  78. int index = hash(entry);
  79. System.out.println(index);
  80. for(int i = 0; i < buckets[index].size(); i++){
  81. if(entry.equals(buckets[index].get(i)))
  82. return true;
  83. }
  84. return false;
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement