实现一个算法确定一个字符串中所有的字符串是否都不相同,假设不允许使用额外的数据结构
一般的解法是如下:
#include<iostream>
using namespace std;
bool noSame(const char* c_str)
{
bool flat = true;
if (*c_str == NULL || *(c_str + 1) == NULL)
return true;
else
{
do{
const char* c_cur = c_str+1;
while (*c_cur != NULL)
{
if (*c_cur == *c_str)
{
flat = false;
break;
}
++c_cur;
}
if (flat == false)
break;
} while (*(++c_str) != NULL && *(c_str + 1) != NULL);
}
return flat;
}
int main()
{
const char* c_str = "ajksda";
if (noSame(c_str))
cout << "Yes" << endl;
else
cout << "No" << endl;
int a;
cin >> a;
return 0;
}