Думаю, что проблема с вводом-выводом, т.к. я свою первую задачу здесь посылаю
package codeforces;
import java.io.*;
public class Letter {
public void solve() {
boolean oj = true;
try {
Reader reader = oj ? new InputStreamReader(System.in) : new FileReader("C:\\temp\\input.txt");
Writer writer = oj ? new OutputStreamWriter(System.out) : new FileWriter("C:\\temp\\output.txt");
BufferedReader br = new BufferedReader(reader);
PrintWriter out = new PrintWriter(writer);
MyTokenizer tok = new MyTokenizer(br.readLine());
int n = (int)tok.getNum();
int m = (int)tok.getNum();
char[][] a = new char[n][m];
for(int i=0;i<n;i++) {
String s = br.readLine();
for(int j=0;j<m;j++) {
a[i][j] = s.charAt(j);
}
}
int minx = Integer.MAX_VALUE, miny = Integer.MAX_VALUE, maxx = Integer.MIN_VALUE,maxy = Integer.MIN_VALUE;
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
if (a[i][j] == '*') {
if (minx > i)
minx = i;
if (miny > j)
miny = j;
if (maxx < i)
maxx = i;
if (maxy < j)
maxy = j;
}
for(int i=minx; i <= maxx;i++) {
for(int j=miny;j<=maxy;j++) {
out.print(a[i][j]);
}
out.print("\n");
}
reader.close();
writer.close();
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
}
}
public static void main(String[] args) {
Letter f = new Letter();
f.solve();
}
private class MyTokenizer {
private String s;
private int cur;
public MyTokenizer(String s) {
this.s = s;
cur = 0;
}
public void skip() {
while (cur < s.length() && (s.charAt(cur) == ' ' || s.charAt(cur) == '\n')) {
cur++;
}
}
public double getNum() {
skip();
String snum = "";
while (cur < s.length() && (s.charAt(cur) >= '0' && s.charAt(cur) <= '9' || s.charAt(cur) == '.')) {
snum += s.charAt(cur);
cur++;
}
return Double.valueOf(snum);
}
public String getString() {
skip();
String s2 = "";
while (cur < s.length() && (s.charAt(cur) >= 'a' && s.charAt(cur) <= 'z')) {
s2 += s.charAt(cur);
cur++;
}
return s2;
}
public char getCurrentChar() throws Exception {
if (cur < s.length())
return s.charAt(cur);
else
throw new Exception("Current character out of string length");
}
public void moveNextChar() {
if (cur < s.length())
cur++;
}
public boolean isFinished() {
return cur >= s.length();
}
}
}