|
-
Oct 1st, 2001, 09:23 PM
#1
Thread Starter
New Member
problem driving me insane!!
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;
}
"go masturbate with a cheese grater"
-
Oct 1st, 2001, 11:10 PM
#2
use pointers.
ansi c version --
Code:
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
char tmp[20];
char n[20];
strcpy(n,"0011233445566789");
memset(tmp,'\0',sizeof(tmp) ); // this avoids placing zero at end of string
dedupe(tmp,n);
printf("%s\n",tmp);
return 0;
}
void dedupe(char *ret, char *in){
char *a,*b,*c;
c=ret;
a=in;
b=a+1;
while (*a!='\0'){
if(*a != *b) *c++=*a;
a++;
b++;
}
}
-
Oct 2nd, 2001, 03:05 PM
#3
Thread Starter
New Member
"go masturbate with a cheese grater"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|