Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //nema pokancer dijalekt though haha
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- class MapEntry<K extends Comparable<K>,E> implements Comparable<K> {
- // Each MapEntry object is a pair consisting of a key (a Comparable
- // object) and a value (an arbitrary object).
- K key;
- E value;
- public MapEntry (K key, E val) {
- this.key = key;
- this.value = val;
- }
- public int compareTo (K that) {
- // Compare this map entry to that map entry.
- @SuppressWarnings("unchecked")
- MapEntry<K,E> other = (MapEntry<K,E>) that;
- return this.key.compareTo(other.key);
- }
- public String toString () {
- return "<" + key + "," + value + ">";
- }
- }
- class SLLNode<E> {
- protected E element;
- protected SLLNode<E> succ;
- public SLLNode(E elem, SLLNode<E> succ) {
- this.element = elem;
- this.succ = succ;
- }
- @Override
- public String toString() {
- return element.toString();
- }
- }
- class CBHT<K extends Comparable<K>, E> {
- // An object of class CBHT is a closed-bucket hash table, containing
- // entries of class MapEntry.
- private SLLNode<MapEntry<K,E>>[] buckets;
- @SuppressWarnings("unchecked")
- public CBHT(int m) {
- // Construct an empty CBHT with m buckets.
- buckets = (SLLNode<MapEntry<K,E>>[]) new SLLNode[m];
- }
- private int hash(K key) {
- // Napishete ja vie HASH FUNKCIJATA
- return Math.abs(hashCode()) % buckets.length;
- }
- public SLLNode<MapEntry<K,E>> search(K targetKey) {
- // Find which if any node of this CBHT contains an entry whose key is
- // equal
- // to targetKey. Return a link to that node (or null if there is none).
- int b = hash(targetKey);
- for (SLLNode<MapEntry<K,E>> curr = buckets[b]; curr != null; curr = curr.succ) {
- if (targetKey.equals(((MapEntry<K, E>) curr.element).key))
- return curr;
- }
- return null;
- }
- public void insert(K key, E val) { // Insert the entry <key, val> into this CBHT.
- MapEntry<K, E> newEntry = new MapEntry<K, E>(key, val);
- int b = hash(key);
- for (SLLNode<MapEntry<K,E>> curr = buckets[b]; curr != null; curr = curr.succ) {
- if (key.equals(((MapEntry<K, E>) curr.element).key)) {
- // Make newEntry replace the existing entry ...
- curr.element = newEntry;
- return;
- }
- }
- // Insert newEntry at the front of the 1WLL in bucket b ...
- buckets[b] = new SLLNode<MapEntry<K,E>>(newEntry, buckets[b]);
- }
- public void delete(K key) {
- // Delete the entry (if any) whose key is equal to key from this CBHT.
- int b = hash(key);
- for (SLLNode<MapEntry<K,E>> pred = null, curr = buckets[b]; curr != null; pred = curr, curr = curr.succ) {
- if (key.equals(((MapEntry<K,E>) curr.element).key)) {
- if (pred == null)
- buckets[b] = curr.succ;
- else
- pred.succ = curr.succ;
- return;
- }
- }
- }
- public String toString() {
- String temp = "";
- for (int i = 0; i < buckets.length; i++) {
- temp += i + ":";
- for (SLLNode<MapEntry<K,E>> curr = buckets[i]; curr != null; curr = curr.succ) {
- temp += curr.element.toString() + " ";
- }
- temp += "\n";
- }
- return temp;
- }
- }
- public class KumanovskiDijalekt {
- public static void main (String[] args) throws IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(
- System.in));
- int N = Integer.parseInt(br.readLine());
- CBHT<String,String> kumanovski_makedonski= new CBHT<>(399);
- String rechnik[]=new String[N];
- for(int i=0;i<N;i++){
- rechnik[i]=br.readLine();
- String[] zbor= rechnik[i].split("\\s+");
- kumanovski_makedonski.insert(zbor[0],zbor[1]);
- }
- String tekst=br.readLine();
- String[] zborovi= tekst.split("\\s+");
- //Vasiot kod tuka
- StringBuilder sb= new StringBuilder();
- for(int i=0;i<zborovi.length;i++){
- String zbor_bez_znak;
- Character znak='$';
- if(zborovi[i].charAt(zborovi[i].length()-1)=='.'||
- zborovi[i].charAt(zborovi[i].length()-1)=='!'||
- zborovi[i].charAt(zborovi[i].length()-1)=='?'||
- zborovi[i].charAt(zborovi[i].length()-1)==','){
- zbor_bez_znak=zborovi[i].substring(0,zborovi[i].length()-1).toLowerCase();
- znak= zborovi[i].charAt(zborovi[i].length()-1);
- }
- else{
- zbor_bez_znak=zborovi[i].toLowerCase();
- }
- if(kumanovski_makedonski.search(zbor_bez_znak)!=null){
- String prevod= kumanovski_makedonski.search(zbor_bez_znak).element.value;
- if(Character.isUpperCase(zborovi[i].charAt(0))) prevod= prevod.substring(0,1).toUpperCase()+prevod.substring(1);
- if(znak!='$') sb.append(prevod).append(znak).append(" ");
- else sb.append(prevod).append(" ");
- }
- else{
- sb.append(zborovi[i]).append(" ");
- }
- }
- System.out.println(sb);
- }
- }
- /*
- 20
- nego otkolku
- pesmu pesna
- bija bil
- u vo
- s’s so
- zhenu zhena
- ubavu ubava
- sakaja sakal
- ednu edna
- poznatu poznata
- pesmu pesna
- umreja umrel
- sliku slika
- zelje zelbi
- rakiju rakija
- ede jade
- skup skap
- chasku chaska
- povishke povekje
- narodnu narodna
- Batko Gjorgjija e tipichna figura i karakter od Kumanovo, koj bija golem majtapdzija i boem i koj povishke sakaja kjef da tera nego da raboti. U ednu poznatu narodnu pesmu vika se deka umreja s’s tri zelje za ubavu zhenu, za chasku rakiju i za skup pajton.
- -----------------------------------------------------------------------------------------------------------------------
- Batko Gjorgjija e tipichna figura i karakter od Kumanovo, koj bil golem majtapdzija i boem i koj povekje sakal kjef da tera otkolku da raboti. Vo edna poznata narodna pesna vika se deka umrel so tri zelbi za ubava zhena, za chaska rakija i za skap pajton.
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement