Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Scanner;
- import java.util.Set;
- import java.util.TreeSet;
- public class MagicStrings {
- public static void main(String[] args){
- Scanner scan=new Scanner(System.in);
- int number=scan.nextInt();
- int count=0;
- int[] weight={3, 4, 1 ,5};
- HashMap<Integer, String> weightMe=new HashMap<Integer, String>();
- Set<String> collection=new TreeSet<String>();
- String result="";
- weightMe.put(3, "s");
- weightMe.put(4, "n");
- weightMe.put(1, "k");
- weightMe.put(5, "p");
- for (int i1 = 0; i1 < 4; i1++) {
- for (int i2 = 0; i2 < 4; i2++) {
- for (int i3 = 0; i3 < 4; i3++) {
- for (int i4 = 0; i4 < 4; i4++) {
- for (int j1 = 0; j1 < 4; j1++) {
- for (int j2 = 0; j2 < 4; j2++) {
- for (int j3 = 0; j3 < 4; j3++) {
- for (int j4 = 0; j4 < 4; j4++) {
- if((weight[i1]+weight[i2]+weight[i3]+weight[i4])-(weight[j1]+weight[j2]+weight[j3]+weight[j4])==number)
- {
- result="" + switcher(i1) + switcher(i2) + switcher(i3) + switcher(i4) + switcher(j1) + switcher(j2) + switcher(j3) + switcher(j4);
- collection.add(result);
- count++;
- }
- else if((weight[i1]+weight[i2]+weight[i3]+weight[i4])-(weight[j1]+weight[j2]+weight[j3]+weight[j4])==(number*-1)){
- result="" + switcher(i1) + switcher(i2) + switcher(i3) + switcher(i4) + switcher(j1) + switcher(j2) + switcher(j3) + switcher(j4);
- collection.add(result);
- count++;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- if(count==0){
- System.out.println("No");
- }
- else{
- for(String alphaCollect : collection){
- System.out.println(alphaCollect);
- }
- }
- }
- public static String switcher(int zeroToFour){
- String result="";
- switch(zeroToFour){
- case 0:
- result="s";
- break;
- case 1:
- result="n";
- break;
- case 2:
- result="k";
- break;
- case 3:
- result="p";
- break;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement