7-4.题目统计
在ACM程序设计竞赛赛场,当某个队伍正确解答一道题目后就会在其前面升起1个彩色气球。而且每种颜色的气球只能用在一道题目上,所以不同颜色的气球不能相互替代。已知比赛过程中已送出的气球数量以及每个气球的颜色,请统计已成功解决的不同题目的总数。
输入格式:
首先输入一个正整数T,表示测试数据的组数,然后是T组测试数据。每组测试先输入一个整数n(1≤n≤100),代表已经送出的气球总数,然后输入n个已送出气球的颜色(由长度不超过20且不包含空格的英文字母组成),数据之间间隔一个空格。注意,统计时,忽略气球颜色的大小写。
输出格式:
对于每组测试,在一行上输出一个整数,表示已成功解决的不同题目的总数。
输入样例:
1 2 3 4 5
   | 4 5 RED Red Blue Green REd 2 Pink pINk 1 YeLLoW 6 Red Blue Orange Blue Red ORANGE
   | 
 
输出样例
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
   | #include <iostream> #include <vector> #include <algorithm> #include <string> using namespace std;
  class Group { public: 	int n;	 	vector<string> ballon;	 };
  int main() { 	int n; 	vector<Group> group;	 	Group temp; 	string temp_str; 	cin >> n; 	for (int i = 0; i < n; ++i) 	{ 		temp.ballon.clear();	 		cin >> temp.n; 		for (int j = 0; j < temp.n; ++j) 		{ 			cin >> temp_str; 			transform(temp_str.begin(), temp_str.end(), temp_str.begin(), toupper);	 			if (!count(temp.ballon.begin(), temp.ballon.end(), temp_str))	 				temp.ballon.push_back(temp_str); 		} 		group.push_back(temp);	 	}
  	for (int i = 0; i < n; ++i) 	{ 		cout << group[i].ballon.size() << endl;	 	} 	return 0; }
   | 
 
ps:如果对于transform函数不太熟悉,请移步c++字符串大小写转换之transform用法