c++ - Wrong Output from Map -


i have problem outputting elements map. code:

#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; } 

for input:

2 6 03 10103538 2222 1233 6160 0142  03 10103538 2222 1233 6160 0141  30 10103538 2222 1233 6160 0141  30 10103538 2222 1233 6160 0142  30 10103538 2222 1233 6160 0141  30 10103538 2222 1233 6160 0142   5 30 10103538 2222 1233 6160 0144  30 10103538 2222 1233 6160 0142  30 10103538 2222 1233 6160 0145  30 10103538 2222 1233 6160 0146  30 10103538 2222 1233 6160 0143  

, have used 1 line key in map. have output key , value decreasing order key.

program's output:

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 

correct output:

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 

am doing wrong?


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -