|
|
back to boardHelp Please WA30!!!! I 'm waiting !! thank you!!! I think my idea completely right What's wrong?????? import java.util.Scanner; public class Main { public static void main(String [] args) { Scanner in = new Scanner(System.in); int n; n = in.nextInt(); String s[][] = new String[n][3]; for(int i=0;i<n;i++){ for(int j=0;j<3;j++){ s[i][j] = in.next(); } } boolean all[][] = new boolean[n][3]; String ss[][] = new String[3*n][3*n]; ss[0][0] = "Isenbaev"; int []index = new int[3*n]; for(int i=0;i<n;i++){ index[i] = 0; } index[0] = 1; int d = 1; for(int i=0;i<n;i++){ for(int j=0;j<3;j++){ if(s[i][j].equalsIgnoreCase("Isenbaev"))all[i][j] = true; } } boolean BOR = false; for(int i=0;i<n;i++){ for(int j=0;j<3;j++){ if(s[i][j].equalsIgnoreCase("Isenbaev"))BOR = true; } } for(int q=0;q<3*n;q++){ boolean bormi = false; for(int i=0;i<n;i++){ boolean bor = false; for(int j=0;j<3;j++){ for(int t=0;t<index[d-1];t++){ if(ss[d-1][t].equalsIgnoreCase(s[i][j])){ bor = true; break; } }if(bor)break; } if(bor){ for(int j=0;j<3;j++){ if(!all[i][j]){ ss[d][index[d]++] = s[i][j]; all[i][j] = true; bormi = true; for(int g=0;g<n;g++){ for(int h=0;h<3;h++){ if(s[g][h].equalsIgnoreCase(s[i][j]))all[g][h] = true; } } } } } } if(bormi)d++; } String []sss = new String[3*n]; int []son = new int[3*n]; for(int i=0;i<3*n;i++){ son[i] = -1; } int koef = 0; for(int i=0;i<d;i++){ if(i==0){ if(BOR){ BOR = false; }else i++; } for(int j=0;j<index[i];j++){ sss[koef] = ss[i][j]; son[koef++] = i; } } for(int i=0;i<n;i++){ for(int j=0;j<3;j++){ if(!all[i][j]){ boolean top = true; for(int p=0;p<koef;p++){ if(sss[p].equalsIgnoreCase(ss[i][j]))top = false; } if(top)sss[koef++] = s[i][j]; } } } n = koef; for(int i=0;i<n-1;i++){ if(sss[i].compareTo(sss[i+1])>0){ String S = sss[i]; sss[i] = sss[i+1]; sss[i+1] = S; int SS = son[i]; son[i] = son[i+1]; son[i+1] = SS; i=-1; } } for(int i=0;i<koef;i++){ if(son[i]!=-1)System.out.println(sss[i] + " " + son[i]); else System.out.println(sss[i] + " undefined" ); } } } Edited by author 25.07.2018 00:30 Edited by author 27.07.2018 23:09 |
|
|