Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class Solution {
- public static void main(String args[]) {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- int m1 = in.nextInt()*n;
- int m=m1;
- char[] alphabet = "ZYXWVUTSRQPONMLKJIHGFEDCBA".toCharArray();
- String sBefore="0";
- String[] string;
- string=new String[m];
- int count=0;
- int amount=-1;
- int best=1;
- String[] values;
- values=new String[1000];
- String best1="error";
- String s="";
- int v = -10000;
- for (int i = 0; i < n; i++) {
- s = in.next()+s;
- }
- System.err.println(s);
- while(true) {
- m=s.length();
- for (int j=0;j<m-1;j++) {
- string[j]=String.valueOf(s.charAt(j))+""+String.valueOf(s.charAt(j+1));
- }
- for (int j=0;j<m-1;j++) {
- for (int k=0;k<m-1;k++) {
- if (string[j].equals(string[k])==true &&v!=k-1) {
- amount++;
- v=k;
- }
- }
- if (amount>best) {
- best=amount;
- best1=string[j];
- }
- amount=-1;
- }
- String s1=s.replaceAll(best1, String.valueOf(alphabet[count]));
- System.err.println(s);
- values[count]=alphabet[count]+" = "+best1;
- s=s1;
- best1="error";
- best=0;
- count++;
- if (sBefore.equals(s)) {
- break;
- }
- sBefore=s;
- }
- System.out.println(s);
- m=m1;
- for (int h=0;h<count-1;h++) {
- System.out.println(values[h]);
- }
- count=0;
- m=m1;
- sBefore="0";
- string=new String[m];
- count=0;
- amount=-1;
- best=1;
- values=new String[1000];
- best1="error";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement