Advertisement
Guest User

Magic Strings

a guest
May 28th, 2014
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.98 KB | None | 0 0
  1. import java.util.HashMap;
  2. import java.util.Scanner;
  3. import java.util.Set;
  4. import java.util.TreeSet;
  5. public class MagicStrings {
  6.     public static void main(String[] args){
  7.         Scanner scan=new Scanner(System.in);
  8.         int number=scan.nextInt();
  9.         int count=0;
  10.         int[] weight={3, 4, 1 ,5};
  11.         HashMap<Integer, String> weightMe=new HashMap<Integer, String>();
  12.         Set<String> collection=new TreeSet<String>();
  13.         String result="";
  14.         weightMe.put(3, "s");
  15.         weightMe.put(4, "n");
  16.         weightMe.put(1, "k");
  17.         weightMe.put(5, "p");
  18.         for (int i1 = 0; i1 < 4; i1++) {
  19.             for (int i2 = 0; i2 < 4; i2++) {
  20.                 for (int i3 = 0; i3 < 4; i3++) {
  21.                     for (int i4 = 0; i4 < 4; i4++) {
  22.                         for (int j1 = 0; j1 < 4; j1++) {
  23.                             for (int j2 = 0; j2 < 4; j2++) {
  24.                                 for (int j3 = 0; j3 < 4; j3++) {
  25.                                     for (int j4 = 0; j4 < 4; j4++) {
  26.                                         if((weight[i1]+weight[i2]+weight[i3]+weight[i4])-(weight[j1]+weight[j2]+weight[j3]+weight[j4])==number)
  27.                                         {
  28.                                             result="" + switcher(i1) + switcher(i2) + switcher(i3) + switcher(i4) + switcher(j1) + switcher(j2) + switcher(j3) + switcher(j4);
  29.                                             collection.add(result);
  30.                                             count++;
  31.                                         }
  32.                                         else if((weight[i1]+weight[i2]+weight[i3]+weight[i4])-(weight[j1]+weight[j2]+weight[j3]+weight[j4])==(number*-1)){
  33.                                             result="" + switcher(i1) + switcher(i2) + switcher(i3) + switcher(i4) + switcher(j1) + switcher(j2) + switcher(j3) + switcher(j4);
  34.                                             collection.add(result);
  35.                                             count++;
  36.                                         }
  37.                                     }
  38.                                 }
  39.                             }
  40.                         }
  41.                     }
  42.                 }
  43.             }
  44.         }
  45.         if(count==0){
  46.             System.out.println("No");
  47.         }
  48.         else{
  49.             for(String alphaCollect : collection){
  50.                 System.out.println(alphaCollect);
  51.             }
  52.         }
  53.     }
  54.     public static String switcher(int zeroToFour){
  55.         String result="";
  56.         switch(zeroToFour){
  57.         case 0:
  58.             result="s";
  59.             break;
  60.         case 1:
  61.             result="n";
  62.             break;
  63.         case 2:
  64.             result="k";
  65.             break;
  66.         case 3:
  67.             result="p";
  68.             break;
  69.         }
  70.         return result;
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement