你至少需要:
我相信这足以让您入门,如果您在实际编写代码时遇到特定问题,请毫不犹豫地提出新问题。
根据您的评论编辑:
您并没有错过太多,elvena 的解决方案几乎是您所需要的,只是它缺少用于存储对象的矢量容器。这很简单:
#include <iostream>
#include <map>
#include <vector>
#include <tuple>
int main()
{
std::vector<std::tuple<int, int, int>> values;
while (you_have_more_data) {
int c1, c2, c3;
// somehow read c1, c2, c3 from cin/file/whatever
values.push_back(std::make_tuple(c1, c2, c3));
}
std::map<int, int> dict;
// iterate over the vector
for (auto i = values.begin(); i != values.end(); ++i) {
// *i (dereferencing the iterator) yields a std::tuple<int, int, int>
// use std::get to access the individual values in the tuple
// 0 => c1; 1 => c2; 2 => c3 (same order as in std::make_tuple)
if (std::get<1>(*i) > 0 && std::get<2>(*i) < 4)
dict[std::get<0>(*i)] += 1; // see std::map::operator[]
}
// iterate over the map and print its items
for (auto i = dict.begin(); i != dict.end(); ++i)
// *i (dereferencing the iterator) yields a std::pair<int, int>
// but writing (*i).first is cumbersome
// let's write i->first instead (this is the same, just a different notation)
std::cout << i->first << " " << i->second << std::endl;
return 0;
}