Priority Que help Counting Letters

Pages: 12
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
#include <iostream>
#include <vector>
using namespace std;

int main()
{
vector<string> first;
string ht = "The quick brown fox jumps over the lazy dog";

int freq=0;

for(int i = 0; i < ht.length(); ++i)
{
	first.push_back(ht.substr(i,1));
}

for (vector<string>::iterator it = first.begin(); it != first.end(); ++it)
{
freq = 1;
for (vector<string>::iterator j = it+1; j != first.end(); ++j)
{
if (*it == *j)
{
freq++;
first.erase(j);
}//if
}//j
cout << *it << "= " << freq << endl;
}

return 0;
}


T= 1
h= 2
e= 3
 = 8
q= 1
u= 2
i= 1
c= 1
k= 1
b= 1
r= 2
o= 4
w= 1
n= 1
f= 1
x= 1
j= 1
m= 1
p= 1
s= 1
v= 1
t= 1
l= 1
a= 1
z= 1
y= 1
d= 1
g= 1

Kemort do I not need

#include<queue>
or
#include<algorithm>
?
I noticed in the code that you presented to me it had errors compiling on lines 82 and 84. And why do I need the system("pause"); wouldn't a cout or something be good?
closed account (48T7M4Gy)
Hi Stl784,

No you don't need the two includes. They're only necessary if you are using them and their functionality in your program and I can't see where they are. You can also test it by simply commenting them out on yours if you like and making sure you get the results you want.

I have fixed the two errors. I was using VS2015 and your program ran OK but the online compiler here was a bit more fussy. I've checked it here this time and it's all good.

system ("pause") is just there for a convenience but can be left out if your don't like it and it's not necessary for running your program online here, so I've deleted it.

Cheers
Thank you very much for the help, I know it was probably taxing for you to answer all my dumb questions haha. So to clarify, the code you've written works, just the compiler on this website is iffy?
Last edited on
closed account (48T7M4Gy)
No they weren't dumb questions. I haven't adjusted VS2015 from the defaults so I just put it down to Microsoft being more tolerant than the shell here. I usually check if it works online but forgot to this time and it bit me. :) / :[

Cheers
Again thank you so so much for all your help :).
Topic archived. No new replies allowed.
Pages: 12