由于只能在源字符串中操作,所以要靠排序,快排中如果跟pivot相同就失败。
/*
Inpmlemement an algorithm to determine if a string has all unique characters What if you
can not use additional data structures?
*/
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int partition(string str, int b, int e){
int j = b + 1;
for (int i = b + 1; i <= e; i++){
if(str[i] < str[b]){
swap(str[i],str[j]);
j++;
}else if (str[i] == str[b]) return -1;
}
swap(str[j],str[b]);
return j;
}
bool judge_qs(string str,int b, int e){
if(b < e){
int p = partition(str,b,e);
if (p == -1 || judge_qs(str,b,p-1) == false || judge_qs(str,p+1,e) == false)
return false;
}
return true;
}
int main()
{
string str;
cin>>str;
cout<<judge_qs(str,0,str.length()-1)<<endl;
}