Time Limit: 1sec Memory Limit:256MB
Description
A pot contains a huge number of balls, and each ball is labelled with some string. Now a random sample is made with replacement, which means when a ball is drawn out and mesured, it is put back into the pot. Now for a given sampling with repalcement, you are required to compute the number of different balls in the sample. For example, if the sample is , then the different number of balls is 5.
在一个罐子里面有一些球,每个球上有一个string标签,现在进行有放回取样,即每次抽出小球观察后再将小球放回容器,比如:
取出了这些标签的小球:Knuth, Dijkstra, Prim, Dijkstra, Knuth, Turing, Dijkstra, Kruskal
那么小球的种类数为5
Input
需要进行多次的放回取样。对于每个样本而言,第一行是一个整数n,指的是取样的次数,之后是n行,每行是取出小球的标签,测试样例以0结束。
Output
对于每一次的放回取样,用一行输出不同小球的个数
Sample Input
Copy sample input to clipboard
2
Knuth
Dijkstra
5
Knuth
Knuth
Dijkstra
Prim
Dijkstra
0
Sample Output
2
3
~( ̄▽ ̄~)(~ ̄▽ ̄)~
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main()
{
int T;
int count;
string str;
map<string, int> pro;
while (cin >> T && T != 0)
{
count = 0;
pro.clear();
while (T--)
{
cin >> str;
if (!pro[str])
{
pro[str]++;
count++;
}
}
cout << count << endl;
}
return 0;
}