[ create a new paste ] login | about

Link: http://codepad.org/uvOGCtEN    [ raw code | output | fork ]

k06a - C++, pasted on Nov 12:
#include <map>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

struct A
{
    string str;
    int count;

    bool operator < (const A & a) const
    {
        return count < a.count;
    }
};

int main()
{
string str = "31419190919949948594067689885149894916794986729154113092"
             "56767360137473010976493689647676073146336791994537492467"
             "68988594394989196979991987919894391072498367666760793492"
             "56787673976699464904981485737916774674019867949111669152"
             "09536739499911085939909909868939116892493191966760709436"
             "73931490936664672396925679193944949236299398399161919256"
             "79991591986770249872669909868676070724984940614925677367"
             "32485986739968736726493394539939009949256795367394859868"
             "78767309601646791925679874924994925675392919466944854639"
             "25678514980996452398164994986867607523626409294010676867"
             "60785916991983949891962498672915411485676079649991168700"
             "52016119196395989391290467689439867329547479466529172498"
             "16693492567524949349766996706300367949167676070924969167"
             "6867919256785239309949868949691986791989839916191966760";

map<string,int> m;
for(unsigned i = 0; i < str.size()-3; i++)
if (str.substr(i,2) == str.substr(i+2,2))
    m[str.substr(i,4)]++;

vector<A> v;
for(map<string,int>::iterator it = m.begin();
    it != m.end(); ++it)
{
    A a = { it->first, it->second };
    v.push_back(a);
}

sort(v.rbegin(), v.rend());

for(unsigned i = 0; i < v.size(); i++)
    cout << v[i].str << ": " << v[i].count << endl;
}


Output:
1
2
3
4
5
6
7
8
9
1919: 5
4949: 2
6767: 2
7676: 2
8686: 2
0707: 1
4747: 1
8787: 1
9898: 1


Create a new paste based on this one


Comments: