void RemoveDuplicate(char *str)
{
int i, j, k;
unsigned long len = strlen(str);
for(i = k = 0; i < len; i++) {
if(str[i]) {
str[k++] = str[i];
for(j = i + 1; j < len; j++)
if(str[j] == str[i])
str[j] = '\0';
}
}
str[k] = '\0';
}
void RemoveDuplicate1(char *s) {
char check[256] = { 0 };
int j = 0;
unsigned long len = strlen(s);
for(int i = 0; i < len; i++) {
if(check[s[i]] == 0) {
s[j++] = s[i];
check[s[i]] = 1;
}
}
s[j] = '\0';
}
void RemoveDuplicate3(char *s) {
int remainder;
int check[8] = {0}; //4個(gè)字節(jié) * 8 * 8bit = 256bit
int j = 0;
unsigned long len = strlen(s);
for(int i = 0; i < len; i++) {
remainder = s[i] % 32; //remainder 范圍0-31
//s[i] >> 5是確定在數(shù)組中哪個(gè)位置
printf("%d -- %d--%d", s[i] >> 5, check[s[i] >> 5], remainder);
printf("\n");
if((check[s[i] >> 5] & (1 << remainder)) == 0) {
s[j++] = s[i];
check[s[i] >> 5] |= (1 << remainder);
}
}
s[j] = '\0';
}
void RemoveDuplicate2(char *s)
{
int i, j, val, check;
j = check = 0;
for(i = 0; s[i]; i++)
{
val = s[i] - 'a';
if((check & (1 << val)) == 0)
{
s[j++] = s[i];
check |= 1 << val;
}
}
s[j] = '\0';
}
字符串去重
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。
相關(guān)閱讀更多精彩內(nèi)容
- 最近收集了些關(guān)于字符串?dāng)?shù)組去重,找重復(fù)數(shù)的方法,記錄于下,分享給大家: 字符串去重, 思路: 先對原來的字符串拆分...
- js字符串去重 1、indexOf方法(無兼容問題) 2、search方法 indexOf方法我們知道是,遍歷字符...
- 數(shù)組去重 一: 二:通過原型鏈 兩個(gè)代碼,一個(gè)是通過原型鏈可像操作數(shù)組一樣使用;一個(gè)是一個(gè)方法傳參數(shù)調(diào)用。都是通過...
- 給我們一串字符串或者文章,我們想知道它用了哪些字符或者去重,可以用這個(gè)方法 結(jié)果: 同樣的列表也可以用這個(gè)方法 結(jié)果: