counting

how can i count total number of each topic separately?
for example total number of topic 1 between all nodes.
to begin enter 10 and 7 to initial node number and number of topic.
#include <iostream>
#include <vector>
#include <list>
#include <stdlib.h>
#include<time.h>
#include<iomanip>
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include<algorithm>
using namespace std;
int main() {
int numberOfNode;
cin>>numberOfNode;
int numberOfTopic;
cin>>numberOfTopic;
srand(time(NULL));

std::vector <std::list<int> > adjList(numberOfNode);
for(int i=0; i<numberOfNode; i++){
int randomSize = rand()% numberOfTopic + 1;
int topicSelection[randomSize];
for(int j=0; j<randomSize; j++){
topicSelection[j] = rand()% numberOfTopic + 1;
for(int k=0; k<j; k++){
if(topicSelection[j]==topicSelection[k]){
topicSelection[j]=0;
}
}
int selecTopic = topicSelection[j];

adjList[i].push_back(selecTopic);
}
}
std::vector<std::list<int> >::iterator i;
int c=0;
int mycount;
int sina=0;

for (std::vector<std::list<int> >::iterator i=adjList.begin(); i !=adjList.end(); ++i){
cout<<"topics for node "<<c <<" are ";
std::list<int> li = *i;
for(std::list<int>::iterator iter = li.begin(); iter!= li.end(); ++iter){
mycount = std::count (li.begin(), li.end(), 5);
cout<<*iter<<",";

}
cout<<endl;
sina = sina + mycount;
c++;

}
cout<<"5 appears:"<< sina <<endl;
}
Please edit your post and make sure your code is [code]between code tags[/code] so that it has line numbers and syntax highlighting, as well as proper indentation.
Topic archived. No new replies allowed.