-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpair.cpp~
102 lines (98 loc) · 1.35 KB
/
pair.cpp~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include<iostream>
#include<string>
using namespace std;
template<class Type1,class Type2> class Pair
{
public:
Type1 first;
Type2 second;
Pair():first(),second()
{
}
Pair(Type1 f,Type2 s):first(f),second(s)
{
}
void makepair(Type1 a,Type2 b)
{
first=a;
second=b;
}
void operator=(Pair <Type1,Type2> & p)
{
this->first=p.first;
this->second=p.second;
}
int operator<(Pair<Type1,Type2> & p)
{
return this->first<p.first;
}
};
template<class Type1,class Type2>class Map
{
private:
Pair<Type1,Type2> p[100];
int i;
public:
Map()
{
i=0;
}
void sort()
{
Pair<Type1,Type2>e,f,t;
for(int j=0;j<i;j++)
{
if(p[i]<p[j])
{
t=p[i];
e=p[j+1];
f=p[j];
int k;
for(k=j;k<i-1;k++)
{
p[k+1]=f;
f=e;
e=p[k+2];
}
p[k+1]=f;
p[j]=t;
break;
}
}
}
void insert(Type1 a,Type2 b=1)
{
for(int j=0;j<i;j++)
{
if(p[j].first==a)
{
p[j].second+=b;
return ;
}
}
p[i].makepair(a,b);
this->sort();
i++;
}
void show()
{
for(int j=0;j<i;j++)
{
cout<<p[j].first<<" "<<p[j].second<<endl;
}
}
};
int main()
{
Pair<string,int>p("ok",1);
//cout<<p.first<<" "<<p.second<<endl;
Map<string,int>m;
string s;
for(int i=0;i<10;i++)
{
cin>>s;
m.insert(s);
}
m.show();
return 0;
}