放回取样(样本容量)

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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值