Occurrence of letters in String

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nivedita prasad
    New Member
    • Dec 2009
    • 7

    Occurrence of letters in String

    hi
    Occurrence of letters in String. Get string from KB of any length & print letters coming maximum time first than second largest….. i.e in descending order.
    program should be implemented using link list n dymami memory allocation.
    Output look like if u enter string aababbbcba
    b 5 times
    a 4 times
    c 1 times just like that


    Regards
    Nivedita Prasad
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    Not sure about "n dymami"(?) and link list part though. Also it prints most frequent in the bottom :(
    #include <map>
    #include <iostream>
    #include <string>
    #include <algorithm>
    using namespace std;
    #define vbe(x)x.begin() ,x.end()
    typedef map<char,int>V; typedef multimap<int,ch ar>S;
    struct cx{V&Q;cx(V&v): Q(v){}void operator()(char q){if(Q.find(q) ==Q.end())Q[q]=0;Q[q]++;}};
    struct rcx{V&Q;S&T;rcx (V&v,S&q):Q(v), T(q){}void operator()(V::v alue_type x){T.insert(S:: value_type(x.se cond,x.first)); }};
    struct pcx{S&Q;pcx(S&q ):Q(q){}void operator()(S::v alue_type x){cout<<x.seco nd<<" "<<x.first<<end l;}};
    int main(){V v;string s;getline(cin,s );
    {cx C(v); for_each(vbe(s) ,C);}
    S q; {rcx C(v,q); for_each(vbe(v) ,C);}
    {pcx C(q);for_each(v be(q),C);}}

    Comment

    Working...