Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
2.1 kB
0
Indexable
Never
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;


public class EarningBiggestPrizeMoney {
	static int n, r, tam, temp;
	static int[][] A = new int[11][10000];
	static int toInt(int[] arr, int m){
		String x = "";
		for(int i = 0; i < m; i++){
			x = x + arr[i];
		}
		return Integer.valueOf(x);
	}
	public static void main(String[] args) throws FileNotFoundException{
		System.setIn(new FileInputStream("Text"));
		Scanner sc = new Scanner(System.in);
		int tc = sc.nextInt();
		for (int Case = 1; Case <= tc; Case++){
			System.out.println("Case #" + Case);
			n = sc.nextInt();
			int n1 = n;
			int m = String.valueOf(n).length();
			r = sc.nextInt();
			int[] arr = new int[20];
			for(int i = 0; i < m;i++){
				arr[i] = n1 % 10;
				n1 = n1 / 10;
			}
			A[0][1] = n;
			int cnt = 1, cnt1 = 0;
			for(int i = 1; i < r; i++){
				cnt = 0;
				for (int j = 0; j < m; j++){
					for(int k = j + 1; k < m; k++){
						if(i != j){
							temp = arr[j];
							arr[j] = arr[k];
							arr[k] = temp;
							int value = toInt(arr, m);
							boolean existed = false;
							for(int ii = 0; ii < cnt1; k++){
								if(A[i][ii] == value){
									existed = true;
									break;
								}
							}
							if(existed){
								A[i][cnt1++] = value;
							}
						}
					}
				}
			}
			
			
			for(int i = 0; i < m; i++){
				System.out.print(arr[i]);
			}
			System.out.println();
		}
	}
	
}



3    // number of testcase

123 1  // number cards, the number of exchange

2737 1 // number cards, the number of exchange

32888 2

Case #1

321

Case #2

7732

Case #3

88832




50
772 8
441296 9
5525 2
114 2
6575 3
0473 7
7321 10
1138 4
53179 9
975054 4
0128 9
50665 7
937 2
55960 5
564 9
50308 8
57308 6
215 4
377088 3
340 1
1136 6
37 2
58 8
1375 8
655673 10
29 4
153 3
583185 8
812 7
361 9
394 5
60153 1
65433 4
267825 10
969 9
027147 10
08343 8
57568 1
805683 8
83 8
97 9
7734 5
5005 7
216926 7
3560 7
50 1
679 9
16813 3
1415 8
751 10