C++ 映射输出错误
我在从地图输出元素时遇到问题。 我的代码:C++ 映射输出错误,c++,stdmap,C++,Stdmap,我在从地图输出元素时遇到问题。 我的代码: #include <iostream> #include <map> #include <string> int main() { int t,n; std::string cont; std::cin >> t; while(t--) { std::cin >> n; std::map<std::string,int> citire;
#include <iostream>
#include <map>
#include <string>
int main()
{
int t,n;
std::string cont;
std::cin >> t;
while(t--)
{
std::cin >> n;
std::map<std::string,int> citire;
std::map<std::string,int>::iterator it;
for(int i=0; i<n; i++)
{
std::getline(std::cin,cont);
citire[cont]++;
}
for(it=citire.begin(); it!=citire.end(); ++it)
std::cout << it->first << " " << it->second << '\n';
std::cout << '\n';
}
return 0;
}
,我在地图上用了一条线作为键。我所要做的就是输出键,它的值是按键降序的
程序输出:
1
03 10103538 2222 1233 6160 0141 1
03 10103538 2222 1233 6160 0142 1
30 10103538 2222 1233 6160 0141 2
30 10103538 2222 1233 6160 0142 1
1
10103538 2222 1233 6160 0142 1
30 10103538 2222 1233 6160 0142 1
30 10103538 2222 1233 6160 0143 23
30 10103538 2222 1233 6160 0144 1
30 10103538 2222 1233 6160 0145 1
30 10103538 2222 1233 6160 0146 1
5 1
正确输出:
03 10103538 2222 1233 6160 0141 1
03 10103538 2222 1233 6160 0142 1
30 10103538 2222 1233 6160 0141 2
30 10103538 2222 1233 6160 0142 2
30 10103538 2222 1233 6160 0142 1
30 10103538 2222 1233 6160 0143 1
30 10103538 2222 1233 6160 0144 1
30 10103538 2222 1233 6160 0145 1
30 10103538 2222 1233 6160 0146 1
我做错什么了吗
03 10103538 2222 1233 6160 0141 1
03 10103538 2222 1233 6160 0142 1
30 10103538 2222 1233 6160 0141 2
30 10103538 2222 1233 6160 0142 2
30 10103538 2222 1233 6160 0142 1
30 10103538 2222 1233 6160 0143 1
30 10103538 2222 1233 6160 0144 1
30 10103538 2222 1233 6160 0145 1
30 10103538 2222 1233 6160 0146 1