acm 字符串排序问题 高手尽快解决一下 要符合要求
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
CBB
Input
The 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.
Output
You should output Case K: in the first line and the sequences of arrangement in the following lines of each case.
Sample Input
2
BAC
BBC
Sample Output
Case 1:
ABC
ACB
BAC
BCA
CAB
CBA
Case 2:
BBC
BCB
CBB
大意就是把输入的一个字符串组合,不能有重复的。输出的顺序也要考虑一下。
------解决方案--------------------作业?
------解决方案--------------------作业题目吧!
自己想想办法啦!
最近是不是学了什么算法这类的东东!
------解决方案--------------------ACM的题java也可以递交的吗 ?
------解决方案--------------------异步通信控制模块? 关联通信分路转接器?
acm什么意思啊
------解决方案--------------------acm-> 美国计算机协会
acm/icpc(acm主办的全球计算机程序设计大赛,常常被简称为acm)
------解决方案--------------------version c++
--
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define DEBUG
using 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++;
}
}