Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.util.*;
- public class Lozinki {
- public static void main (String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- int N = Integer.parseInt(br.readLine());
- HashTable<User> hashTable = new HashTable<User>(2*N);
- for(int i=1;i<=N;i++){
- String imelozinka = br.readLine();
- String[] pom = imelozinka.split(" ");
- hashTable.insert(new User (pom[0], pom[1]));
- }
- String line = br.readLine();
- while(!line.equals("KRAJ")){
- String[] pom = line.split(" ");
- if(hashTable.find(new User (pom[0], pom[1]))){
- System.out.println("Najaven");
- break;
- }
- else
- System.out.println("Nenajaven");
- line = br.readLine();
- }
- br.close();
- }
- }
- class User{
- String username;
- String password;
- public User(String _username, String _password){
- username = _username;
- password = _password;
- }
- public String getUsername(){
- return username;
- }
- public String getPassword(){
- return password;
- }
- public int hashCode(){
- return Math.abs(username.hashCode());
- }
- public String toString(){
- return username + " " + password;
- }
- public boolean equals(User other){
- if(other == null) return false;
- if(other == this) return true;
- if(other.username.equals(username) && other.password.equals(password))
- return true;
- return false;
- }
- }
- class HashTable<E>{
- List<User> buckets [];
- @SuppressWarnings("unchecked")
- public HashTable(int m){
- buckets = (ArrayList<User> []) new ArrayList[m];
- for(int i = 0; i < m; i++){
- buckets[i] = new ArrayList<User>();
- }
- }
- public void insert(User ins){
- int index = hash(ins);
- buckets[index].add(ins);
- }
- public int hash(User U){
- return U.hashCode()%buckets.length;
- }
- public boolean find(User entry){
- int index = hash(entry);
- System.out.println(index);
- for(int i = 0; i < buckets[index].size(); i++){
- if(entry.equals(buckets[index].get(i)))
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement