-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCount larger appearance.cpp
62 lines (48 loc) · 1.24 KB
/
Count larger appearance.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
/***
I love you <3
picchi baccha marbo accha, soja hoye jabi saccha, picchi bacchaaa
sotti bolchi tomake ar valobasi naa, naa, naa, naaaa
charpoka charpoka charpoka pakha kete dibo :-P
khaj kata khaj kata khaz kata
hur hur hur
hm hmm hmmm hmm hmz hmz
***/
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main ()
{
string str,s;
int len,i,j,maxi,pos,kase=1;
while (getline(cin,str))
{
stringstream ss(str);
vector <string> v;
vector <int> k;
while (ss >> s)
v.push_back(s);
len = v.size();
for (i=0; i<len-1; i++)
{
int count = 0;
for (j=i+1; j<len; j++)
if (v[i] == v[j])
count++;
k.push_back(count);
}
len = k.size(),maxi = k[0], pos = 0;
for (i=1; i<len; i++)
{
if (k[i] > maxi)
{
maxi = k[i];
pos = i;
}
}
printf ("Case %d : ",kase++);
cout << v[pos] << " appears most times (" << k[pos]+1 << ") in " << pos+1 << " position.\n\n";
}
return 0;
}