Given a string of letters(A-Z),your task is to arrange them in alphabetic order.
Following is an example:
A string "BAC" contains 3 letters B,A and C,you should output
ABC
ACB
BAC
BCA
CAB
CBA
In the output file.
A string may contain several letters same,for example "BBC" you should output like this:
BBC
BCB
CBBInputThe first line of input contains a single integer t, the number of test cases,followed by the input data for each test data.Each test case is a string of n(1<=n<=26) letters.OutputYou should output Case K: in the first line and the sequences of arrangement in the following lines of each case.Sample Input2
BAC
BBCSample OutputCase 1:
ABC
ACB
BAC
BCA
CAB
CBA
Case 2:
BBC
BCB
CBB 大意就是把输入的一个字符串组合,不能有重复的。输出的顺序也要考虑一下。

解决方案 »

  1.   

    ACM的题java也可以递交的吗 ?
      

  2.   

    异步通信控制模块? 关联通信分路转接器?
    acm什么意思啊
      

  3.   

    acm->美国计算机协会
    acm/icpc(acm主办的全球计算机程序设计大赛,常常被简称为acm)
      

  4.   

    version c++
    --
    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<vector>#define DEBUGusing namespace std;int cnt[26];
    int tempCnt[26];
    int index[26];
    int indexMax = 0;
    void dfs(int dept,int deptMax,string ts){
         if(dept==deptMax){
                            cout<<ts<<endl;
                            return;
         }
         for(int i=0;i<indexMax;i++){
                if(tempCnt[index[i]]< cnt[index[i]]){
                  tempCnt[index[i]]++;
                  string ts2  = ts;
                  ts+=(char)(index[i]+'A');
                  dfs(dept+1,deptMax,ts);  
                  tempCnt[index[i]]--;      
                  ts = ts2; 
                }            
        }
         
    }
         void solve(string s){
        memset(cnt,0,sizeof(cnt));
        memset(tempCnt,0,sizeof(tempCnt));
        for(int i=0;i<s.size();i++){
                int v = (int)(s[i]-'A');            
                cnt[v]++;
        }
        int ti = 0;
        indexMax = 0;
        for(int i=0;i<26;i++){
          if(cnt[i]>0){
              index[ti++]=i;
              indexMax++;
          }
        }
        dfs(0,s.size(),""); 
    }
    int main(){
        #ifdef      DEBUG
        freopen("data.in","r",stdin);
        freopen("data.out","w",stdout);
        #endif
        
        int cases;
        cin>>cases;
        int caseIndex=0;
        while(cases-- ){
          cout<<"Case "<<caseIndex<<":"<<endl;
          caseIndex++;
          string s;
          cin>>s;      
          solve(s);
        }
        return 0;
    }
          
        
      

  5.   

    version java的就不提供了,除了tc及pku可以用java提交,其它的好像都不支持java的uva不知道能不能用java的,toj好像也可以用java的