@sharad : Thanx !! But is it really O(K) ? if you use map<char,int> for say "AMAZON" you need 5 (chars) + ( 5*4) ( ints) = 25 bytes. + some more space due to MAP structure One more char and you are crossing 26 bytes solution provided by Jalaj. Think about storing "Allodoxaphobia" A= 3 , L = 2 O = 3 , D = 1 X = 1 P =1 H = 1 B = 1 I = 1 , 9 chars so 9* ( 1+4) = 45 bytes !!!
Using uint8_t char_array[26] would have been cheaper ( uint8_t is typedef of unsigned char ) ?? Am I correct ? -Manish PS: I am not a student , working as device modeling guy at a semiconductor company where we don't use Algorithms at all :( Joined this community recently to brush up my long-forgotten skills :) On May 16, 5:10 pm, sharad kumar <[email protected]> wrote: > @Modelling expert. > > #include<iostream> > #include<map> > #include<string> > using namespace std; > int main() > { > string s="amazon"; > int i=0,j=0; > map<char,int>mp; > for(i=0;i<s.length();++i) > { > mp[s.at(i)]++; > } > for(i=0;i<s.length();++i) > { > cout<<s.at(i)<<mp[s.at(i)]; > } > cin.sync(); > cin.get(); > return 0; > } > PS.r u from Institute of mathematical Research science or CMI ....... > > On Sun, May 16, 2010 at 1:50 PM, Modeling Expert < > > > > [email protected]> wrote: > > @sharad : Can you explain with same 'amazon' example for key mapping. > > if we have O(K) hash map, how would we map keys as We need to > > 'remember' mapping to print things back . > > e.g. ASCII valueof (C1)% sizeof(string) could be equal to > > valueof(C2)%sizeof(string) where strins is "C1C2..." > > > @divya your solution looks OK to me , its would be O(k) for space, > > time O ( KlgK) , right ? > > > On May 14, 8:20 am, sharad kumar <[email protected]> wrote: > > > cant u use a hash map ???? of O(K) where K is distinct elements in > > > string...... > > > > On Thu, May 13, 2010 at 8:13 PM, jalaj jaiswal < > > [email protected]>wrote: > > > > > input a character array from the user and output in the following way. > > > > example string is amazon.. then output should be a2m1z1o1n1 > > > > > i did it taking a 26 size array... some better solution ?? > > > > > -- > > > > With Regards, > > > > Jalaj Jaiswal > > > > +919026283397 > > > > B.TECH IT > > > > IIIT ALLAHABAD > > > > > -- > > > > You received this message because you are subscribed to the Google > > Groups > > > > "Algorithm Geeks" group. > > > > To post to this group, send email to [email protected]. > > > > To unsubscribe from this group, send email to > > > > [email protected]<algogeeks%[email protected]> > > <algogeeks%[email protected]<algogeeks%[email protected]> > > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/algogeeks?hl=en. > > > > -- > > > yezhu malai vaasa venkataramana Govinda Govinda > > > > -- > > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > > To post to this group, send email to [email protected]. > > > To unsubscribe from this group, send email to > > [email protected]<algogeeks%[email protected]> > > . > > > For more options, visit this group athttp:// > > groups.google.com/group/algogeeks?hl=en. > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]<algogeeks%[email protected]> > > . > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=en. > > -- > yezhu malai vaasa venkataramana Govinda Govinda > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/algogeeks?hl=en. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
