#include <iostream>
#include <fstream>
#include <map>
#include <string>

using namespace std;

int main() 
{
	// create a map
	//	key : name
	//  value : score

	//map<string, int> scores;

	// add key, value pair
	//scores["John"] = 80;
	//scores["David"] = 90;
	//scores["Minho"] = 100;

	// access value by key
	//cout << scores["Minho"] << endl;

	// pair class
	//pair<string, int> a_score("Scott", 85);
	//cout << a_score.first << ", " << a_score.second << endl;

	//cout << "Number of scores: " << scores.size() << endl;

	// delete a score
	//scores.erase( "Minho" );
    //cout << "Number of scores after delete: " << scores.size() << endl;

	// finding a data by key
	/*if( scores.find("Obama") != scores.end() )
		cout << "Obama's score is " << scores["Obama"] << endl;
	else
		cout << "Obama is not found" << endl;
	*/

	// iterating map
	/*for( map<string, int>::iterator p = scores.begin();
		 p != scores.end();
		 p++ ) {
		cout << p->first << "'s score is " << p->second << endl;
	}*/
	map<string,string> scoremap;

	ifstream scores("scores.txt");
	string line, name, score;
	while( !scores.eof() ){
		/* parsing by delimeter */
		//getline( scores, name, ',' );
		//getline( scores, score, '\n' );
		
		/* parsing by substring */
		getline( scores, line );
		int pos = line.find(",");
		name = line.substr(0,pos);
		score = line.substr(pos+1);

		cout << name << ", "<< score << endl;
		scoremap[name] = score;
	}

	string who;
	do {
		cout << "Please enter name: ";
		cin >> who;
		if( who == "quit" )
			break;
		cout << ">> " << who << "'s score is " << scoremap[who] << endl;
	}while(1);

	
	system("pause");
}