[ create a new paste ] login | about

Link: http://codepad.org/girfIWWw    [ 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()-1; i++)
    m[str.substr(i,2)]++;

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:
67: 51
49: 41
91: 37
98: 32
94: 31
99: 27
39: 25
19: 25
76: 23
92: 18
79: 17
86: 16
09: 15
93: 15
96: 14
16: 14
73: 14
68: 14
66: 13
89: 13
36: 13
56: 12
85: 12
69: 11
25: 11
24: 11
60: 11
64: 10
46: 10
07: 10
29: 8
72: 8
14: 8
59: 8
87: 8
11: 8
90: 8
52: 7
74: 6
48: 6
01: 6
70: 6
23: 5
30: 5
53: 5
78: 5
40: 5
31: 4
83: 4
63: 4
15: 4
61: 4
10: 4
06: 4
95: 4
54: 4
43: 4
97: 4
47: 4
81: 3
77: 3
75: 3
00: 3
45: 3
41: 3
37: 3
62: 3
34: 3
26: 3
44: 2
51: 2
33: 2
13: 2
20: 2
88: 2
32: 2
04: 2
02: 1
03: 1
05: 1
57: 1
08: 1
12: 1
84: 1
17: 1
65: 1
80: 1


Create a new paste based on this one


Comments: