Guest User

Untitled

a guest
Oct 17th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1.  
  2. public class SolutionA {
  3.  
  4.    
  5.     public static void main(String[] args) {
  6.        
  7.         char[] letters = {'A','B','C','D','E','F','G','H','I'};
  8.         char[] password = new char[4];
  9.         int[] pos = new int[4];
  10.        
  11.         for(int i = 0; i<4;i++){
  12.             pos[i] = 0;
  13.         }
  14.        
  15.         boolean running = true;
  16.        
  17.         while(running){
  18.             //i < n
  19.             for(int i= 0; i < 4; i++){
  20.                
  21.                 //i == n-1
  22.                 if(i == 3) {
  23.                     password[i] = letters[pos[i]++];
  24.            
  25.                     if(pos[i] == letters.length) {             
  26.                         for(int j = 3; j>=0; j--) {
  27.                            
  28.                             if((j !=3 &&  pos[j] != letters.length-1) || (j == 3 && pos[j] != letters.length)) {
  29.                                 pos[j]++;
  30.                                 break;
  31.                             }
  32.                             else if(j == 0 && pos[j] == letters.length-1) {
  33.                                 running = false;
  34.                             }
  35.                             else {
  36.                                 pos[j] = 0;
  37.                             }
  38.                         }
  39.                     }
  40.                 }
  41.  
  42.                 else {
  43.                     password[i] = letters[pos[i]];
  44.                 }
  45.             }
  46.             boolean correct = true;
  47.             if(password[0] != 'D' && password[0] != 'H' ) {
  48.                 correct = false;
  49.             }
  50.             for(int i = 0; i<4;i++){
  51.                 if(i <3){
  52.                     if(password[i] == 'G' && password[i+1] == 'A'){
  53.                         correct =false;
  54.                     }
  55.                     else if(password[i] == 'A' && password[i+1] == 'G'){
  56.                         correct = false;
  57.                     }
  58.                 }
  59.             }
  60.            
  61.             for(int i = 0; i<4;i++){
  62.                 if(i <3){
  63.                     if(password[i] == 'B' && (password[i+1] != 'B' && password[i+1] != 'C')){
  64.                         correct =false;
  65.                     }
  66.                 }
  67.             }
  68.            
  69.             if(correct) {
  70.                 System.out.println(password);
  71.             }
  72.         }
  73.     }
  74. }
Add Comment
Please, Sign In to add comment