拼多多笔试题第二题解。。
第二题写的好乱,但是笔试的时候根本不考虑这个了。。。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
char[][] c = new char[n][m];
for(int i=0;i<n;i++){
String str = in.next();
c[i] = str.toCharArray();
}
for(int i=0;i<m;i++){
boolean f = false;
int count1 = 0;
int count2 = 0;
int last = 0;
for(int j=0;j<n;j++){
if(c[j][i]=='x'){
f = true;
for(int p=0;p<count2;p++){
c[p+last][i] = '.';
}
for(int p=0;p<count1;p++){
c[p+last+count2][i] = 'o';
}
count1 = 0;
count2 = 0;
last = j+1;
}else if(c[j][i]=='o'){
count1 ++;
}else if(c[j][i]=='.'){
count2 ++;
}
}
if(f==false){
for(int j=0;j<n;j++)
c[j][i] = '.';
}
for(int p=last;p<n;p++){
c[p][i] = '.';
}
}
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
System.out.print(c[i][j]);
}
System.out.println("");
}
}
}
#拼多多##题解#