您的位置:首页 > 其它

cracking the coding interview problem solution 1.3

2013-06-12 18:00 429 查看
#include "stdafx.h"
#include <algorithm>

#define MAX_LENGTH 500

void delDuplicate(char* pStr, int iStrlen)
{
int iLargeLabel = 0;
int iSmallLabel = 0;

int i0 = 0;
int ikey;
for(int i = 0; i < iStrlen; i++)
{
ikey = pStr[i] - 'A';
if(ikey < 26)
{
if( ((iLargeLabel >> ikey) & 1) == 0 )
{
iLargeLabel += 1<<ikey;
pStr[i0] = pStr[i];
i0++;
}

}
else
{
ikey = pStr[i] - 'a';
if( ((iSmallLabel >> ikey) & 1) == 0 )
{
iSmallLabel += 1<<ikey;
pStr[i0] = pStr[i];
i0++;
}
}
}
pStr[i0] = pStr[iStrlen];
}

int main()
{
char pStrInput[MAX_LENGTH];
scanf("%s", pStrInput);

int iLen = 0;
while(pStrInput[iLen++] != '\0')
continue;
iLen--;

if(iLen == 0)
printf("the string is empty\n");
else
{
delDuplicate(pStrInput, iLen);
printf("the new string is %s\n", pStrInput);
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: