hi, im in advanced computer science in school, and i have this horrible problem, i can't seem to stop my brain from boggling over it for days.
how do i remove duplicates out of a string!!???
if i input this string, "4751244"
i need to output 1 2 4 5 7 as the numbers that the string is made of.
i can sort the string, so the string is 1244457 sorted, now i need someway to check to see if the string has duplicates and remove it!
please post a source or help me understand! here is what i have so far!
void Integer :: digits()
{
int countplace = 0;
int placeCount = 0;
int temp = 0;
int minIndex = 0;
int a = 0;
apstring mynum2 = mynum;
for(int counter = 0; counter < mynum2.length() - 1; counter++)
{
minIndex = counter;
for(placeCount = counter + 1; placeCount < mynum2.length(); placeCount++)
{
if(mynum2[placeCount] < mynum2[minIndex])
minIndex = placeCount;
}
temp = mynum2[minIndex];
mynum2[minIndex] = mynum2[counter];
mynum2[counter] = temp;
}
apstring mynum3 = " ";
for(int i = 0; i < mynum2.length() - 1; i++)
{
if(mynum2[i] == mynum2[i+1])
a = 1;
if (a == 0)
{
mynum3 += mynum2[i];
mynum3 += mynum2[i+1];
a = 0;
}
a = 0;
}
cout << mynum3;
}




Reply With Quote