zoukankan      html  css  js  c++  java
  • 递归全排列字符串

    package com.donghao.anagram;

    import java.util.Scanner;

    public class AnagramApp {
    static int size;
    static int count;
    static char[] arrChar = new char[100];
    static int flag = 0;

    public static void main(String[] args){
    System.out.println("Please enter a word");
    Scanner scan = new Scanner(System.in);
    String input = scan.nextLine();
    size = input.length();
    count =0;
    for(int j=0;j<size;j++){
    arrChar[j] = input.charAt(j);
    }

    doAnagram(size);
    }
    public static void doAnagram(int newSize){

    if(newSize ==1)
    return;
    for(int j=0;j<newSize;j++){
    doAnagram(newSize -1);
    //System.out.println("newSize:" + newSize);
    if(newSize ==2){
    //System.out.println("flag:" + flag++);
    displayWord();
    }

    rorate(newSize);
    }
    }
    public static void rorate(int newSize){
    int j;
    int position = size - newSize;
    char temp = arrChar[position];
    for(j=position+1;j<size;j++){
    arrChar[j-1] = arrChar[j];
    }
    arrChar[j-1] = temp;

    }
    public static void displayWord(){
    if(count <99)
    System.out.print(" ");
    if(count <9)
    System.out.print(" ");
    System.out.print(++count + " ");
    for(int j=0;j<size;j++)
    System.out.print(arrChar[j]);
    System.out.print(" ");
    if(count % 6 ==0)
    System.out.println(" ");
    }
    }

  • 相关阅读:
    数组的反转和二维数组
    初识数组
    Python学习笔记-Day8
    Python学习笔记-Day7
    Python学习笔记-Day6
    Python学习笔记-Day5
    Python学习笔记-Day4
    Python学习笔记-Day3
    Python学习笔记-Day2
    Python学习笔记-Day1
  • 原文地址:https://www.cnblogs.com/xunmengyoufeng/p/2711271.html
Copyright © 2011-2022 走看看