Thread: Could Be Simple
View Single Post
Old Nov 14th, 2004, 2:42 PM   #5
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 406
Rep Power: 5 xavier is on a distinguished road
Send a message via Yahoo to xavier
the problem is that i can't get all the common ellements into another char[]
Example:
c1:abbc
=========>c3:aaabbbbcc this is what i'm having problems getting.
c2:bbbcdaa

even if i sort first the 2 strings :
c1:abbc
c2:aabbbcd

I can't just comare the 2 and put them in c3. For example the first 'a' would be put in twice !!!!
I thaught about reducing the strings:
s1:abc
s2:abcd

Then compare c1 with s2 and c2 with s1 --> then put what's commone from each in c3 ... after that it would be simple.

private static int removeExtra(char a[]){
 int i;
        int d=a.length;
 for(i=0;i<a.length-1;i++){
 	if(a[i]==a[i+1]){
  a[i]=a[i+1];
  d--;
 	}
         }
      }

that's how i'm thinking of doing it. but i have to return th letters that remain .. and not sure how to do it...... and what to write in main.

Hmmmmmm.......... <_<
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote