-
Notifications
You must be signed in to change notification settings - Fork 0
/
V6.java
127 lines (101 loc) · 3.7 KB
/
V6.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import java.util.Scanner;
import java.io.File;
import java.lang.Character;
public class V6 {
public static void main(String[] args) throws Exception{
String s = odkodiraj(args[0], args[1]);
System.out.println(s);
String s2 = kodiraj("v61.txt", "pomlad pomlad pomlad");
System.out.println(s2);
}
public static String odkodiraj(String kodirnaKnjiga, String koda) throws Exception {
Scanner sc = new Scanner(new File(kodirnaKnjiga));
Scanner sc2 = new Scanner(new File(koda));
StringBuilder sb = new StringBuilder();
String readText = "";
String[] splitText;
String rezultat;
while(sc2.hasNextLine()) {
sb.append(sc2.nextLine());
sb.append(" ");
}
//String presplitKoda = sb.toString().replace("0", "");
String[] splitKoda = sb.toString().trim().split("\\s+");
sb = new StringBuilder();
while(sc.hasNextLine()) {
sb.append(sc.nextLine());
sb.append(" ");
}
readText = sb.toString();
splitText = readText.split(" ");
sb = new StringBuilder();
int zeroCounter = 0;
for(int i=0; i < splitKoda.length; i+=2) {
while(Integer.parseInt(splitKoda[i]) == 0) {
zeroCounter++;
i++;
}
int index = Integer.parseInt(splitKoda[i]);
String beseda = splitText[index-1];
char crka = beseda.charAt(Integer.parseInt(splitKoda[i+1])-1);
switch (zeroCounter) {
case 1:
crka = Character.toUpperCase(crka);
break;
case 2:
sb.append(" ");
break;
case 3:
sb.append("\n");
break;
}
sb.append(crka);
zeroCounter = 0;
//sb.append(splitText[Integer.parseInt(splitKoda[i])].charAt(splitKoda[i+1]));
}
rezultat = sb.toString();
return rezultat;
}
public static String kodiraj(String kodirnaKnjiga, String niz) throws Exception{
Scanner sc = new Scanner(new File(kodirnaKnjiga));
StringBuilder sb = new StringBuilder();
String readText = "";
String[] splitText;
String rezultat;
String[] znaki = niz.split("");
while(sc.hasNextLine()) {
sb.append(sc.nextLine());
sb.append(" ");
}
readText = sb.toString();
splitText = readText.split(" ");
for(String b: splitText) {
System.out.println(b);
}
sb = new StringBuilder();
boolean found = false;
for (String c: znaki) {
if (c.equals(" ")) {
sb.append("0 0 ");
continue;
}
for (Integer i=0; i < splitText.length; i++) {
if (splitText[i].indexOf(c) >= 0) {
Integer in = i + 1;
Integer ind = splitText[i].indexOf(c) + 1;
String s = (in).toString() + " " + ind.toString();
sb.append(s);
found = true;
splitText[i] = "+";
break;
}
}
if (found == false ) {
sb.append("99 99");
}
sb.append(" ");
found = false;
}
return sb.toString();
}
}