/* Demonstration of using a C++ Standard Library template Problem: Work out total scores of a class of students. Input: A sequence of pairs: student id (string) + score Output: For each student id the sum of the scores fore that student Style: Quick and dirty File: scoring.cpp Source: Based on an example in Bjarne Stroustup's text on C++ prgramming. Author: R J Botting Started: Nov 11 1998, 9pm Update: Jun 8th 2009 RJB */ #include #include #include using namespace std; typedef map MSI; /* MSI's are sets of pairs(s, score[s]). */ int main() { MSI score; /* for each student_id si on the input, score[si] will equal the sum of the scores for student si */ string si;//student id on input int sc;//score for student id si while( cin>>si>>sc ) score[si] = score[si] + sc; for( MSI::iterator p= score.begin(); p!=score.end(); p++) cout << (*p).first << "\t" << (*p).second <