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);
}
}
#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);
}
}
相关文章推荐
- cracking the coding interview problem solution 1.5
- cracking the coding interview problem solution 1.8
- Cracking the Coding Interview Q1.3
- cracking the code interview problem 1.3
- Cracking The Coding Interview 1.3
- Cracking The Coding Interview 3rd -- 1.3
- cracking the coding interview No1.3
- Cracking The Coding Interview 3rd -- 1.5*
- Cracking the coding interview--Q1.3
- Cracking the coding interview--Q1.6
- 《Cracking the Coding Interview》——第10章:可扩展性和存储空间限制——题目7
- Cracking the coding interview--Q1.1
- 《Cracking the Coding Interview》——第14章:Java——题目6
- Cracking the coding interview--Q20.12
- cracking the coding interview No1.1
- Cracking the coding interview--Q1.7
- 《Cracking the Coding Interview》——第17章:普通题——题目8
- Cracking the coding interview--Q1.8
- 《Cracking the Coding Interview》——第18章:难题——题目6
- Cracking the coding interview--Q2.1