View Code of Problem 9

#include <iostream>
#include <string>
#include <map>
#include <vector>
using namespace std;

int score(int n, vector<string> goat) {
	int res = 0;
	int ath = 0;
	map<string, int> goat_score = { {"Pleasant goat",5},{"Pretty goat",8},{"Athletic goat",10},{"Lazy goat",15},{"Slow goat",20} };
	for (int i = 0; i < n; i++) {
		if (goat[i] == "Athletic goat")
			ath = 1;
	}
	if (n >= 10 && ath == 1) {
		res = res + 10;
	}
	for (string i : goat) {
		res = res + goat_score[i];
	}
	return res;
}
int main() {
		int num=5;
		vector<int> res;
		do {
			cin >> num;
			vector<string> goat(num);
			for (int i = 0; i < num; i++) {
				cin >> goat[i];
			}
			res.push_back(score(num, goat));
		} while (num != EOF);
		for (int i = 1; i <= res.size(); i++) {
			cout << "Case #" << i << ": " << res[i - 1];
		}
		return 0;
}

Double click to view unformatted code.


Back to problem 9