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.HashMap;
- public class KumanovskiDijalekt {
- public static void main(String[] args) throws NumberFormatException, IOException {
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- int N = Integer.parseInt(br.readLine());
- HashMap<String, String> map = new HashMap<String, String>(N);
- for (int i = 0; i < N; i++) {
- String[] pom = br.readLine().split(" ");
- map.put(pom[0], pom[1]);
- }
- String tekst = br.readLine();
- String[] zborovi = tekst.split(" ");
- StringBuilder sb = new StringBuilder();
- String znak = null;
- String word = null;
- if (N == 0) {
- System.out.print(tekst);
- return;
- }
- String result;
- String bukvaGolema;
- String ostatok;
- String konecenZborSoGolemaBukva;
- for (int i = 0; i < zborovi.length; i++) {
- word = zborovi[i];
- znak = null;
- if (zborovi[i].contains(".")) {
- word = zborovi[i].substring(0, zborovi[i].length() - 1);
- znak = ".";
- }
- if (zborovi[i].contains(",")) {
- word = zborovi[i].substring(0, zborovi[i].length() - 1);
- znak = ",";
- }
- if (zborovi[i].contains("!")) {
- word = zborovi[i].substring(0, zborovi[i].length() - 1);
- znak = "!";
- }
- if (zborovi[i].contains("?")) {
- word = zborovi[i].substring(0, zborovi[i].length() - 1);
- znak = "?";
- }
- result = map.get(word.toLowerCase());
- if (result == null) {
- sb.append(zborovi[i] + " ");
- } else {
- if ((i > 0 && zborovi[i - 1].endsWith(".") || i == 0)) {
- bukvaGolema = result.substring(0, 1).toUpperCase();
- ostatok = result.substring(1, result.length());
- konecenZborSoGolemaBukva = bukvaGolema + ostatok;
- if (znak != null)
- sb.append(konecenZborSoGolemaBukva + znak + " ");
- else
- sb.append(konecenZborSoGolemaBukva + " ");
- } else {
- if (znak != null)
- sb.append(result + znak + " ");
- else
- sb.append(result + " ");
- }
- }
- }
- String konecna = sb.toString().trim();
- System.out.println(konecna);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement