(UVA) Decoding the message - Solution
Link to the problem: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=738&page=show_problem&problem=2161
import java.io.*;
import java.util.*;
class Main {
public void process() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int numTests = Integer.parseInt(br.readLine());
br.readLine(); // blank space after the number of tests
for (int test = 0; test < numTests; test++) {
if (test > 0) {
bw.write("\n"); // blank line between tests
}
bw.write("Case #"+(test+1)+":\n");
String line = br.readLine();
while (!line.equals("")) {
String[] s = line.split(" ");
int considering = 1;
for (int i = 0; i < s.length; i++) {
if (s[i].length() < considering) {
continue;
}
bw.write(String.valueOf(s[i].charAt(considering-1)));
considering++;
}
bw.write("\n");
line = br.readLine();
}
}
bw.flush();
bw.close();
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
import java.io.*;
import java.util.*;
class Main {
public void process() throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int numTests = Integer.parseInt(br.readLine());
br.readLine(); // blank space after the number of tests
for (int test = 0; test < numTests; test++) {
if (test > 0) {
bw.write("\n"); // blank line between tests
}
bw.write("Case #"+(test+1)+":\n");
String line = br.readLine();
while (!line.equals("")) {
String[] s = line.split(" ");
int considering = 1;
for (int i = 0; i < s.length; i++) {
if (s[i].length() < considering) {
continue;
}
bw.write(String.valueOf(s[i].charAt(considering-1)));
considering++;
}
bw.write("\n");
line = br.readLine();
}
}
bw.flush();
bw.close();
return;
}
public static void main(String[] args) throws NumberFormatException, IOException {
Main m = new Main();
m.process();
System.exit(0);
}
}
Comments
Post a Comment