Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class testtunhiphan {
- public static void main(String[] arg) {
- int dem = 1;
- System.out.print("Nhap chieu dai: ");
- Scanner scn = new Scanner(System.in);
- int n = scn.nextInt();
- char a[] = new char[n];
- int last = 0;
- for (int i = 0; i < n; i++) {
- a[i] = 'a';
- }
- while (last < n) {
- // in ra dãy bit
- System.out.print(dem++ + " ");
- for (int i = 0; i < n; i++) {
- System.out.print(a[i]);
- }
- System.out.println();
- // nếu bit ở vị trí last chuyển thành z thì nhảy lên một bước.
- if (a[last] == 'z')
- last += 1;
- for (int i = n - 1; i >= 0; i--) {
- if (a[i] != 'z') {
- a[i]++;
- break;
- } else {
- a[i] = 'a';
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment