当前位置: 编程技术>c/c++/嵌入式
如何实现一定概率选中某一个字母
来源: 互联网 发布时间:2014-10-17
本文导语: 在C#版看到这一篇文章,手边现在正开著MacBook上网实在不太想重新开Windows跟Visual Studio来编码正好我也在练习C++ Template,那就很刚好试著用Template来实践一下 代码如下://// main.cpp// RandomTest//// Created by Cloud on 2011/4/10.// Copyright ...
在C#版看到这一篇文章,手边现在正开著MacBook上网
实在不太想重新开Windows跟Visual Studio来编码
正好我也在练习C++ Template,那就很刚好试著用Template来实践一下
//
// main.cpp
// RandomTest
//
// Created by Cloud on 2011/4/10.
// Copyright 2011年 Orz. All rights reserved.
//
#include
#include
using namespace std;
template
class RandomWord
{
T m_Word;
int m_Probability;
public:
RandomWord(T word, int probability):m_Word(word),m_Probability(probability){}
T getWord() { return m_Word; }
int getProbability() { return m_Probability; }
};
template
class RandManager
{
vector m_randomList;
int m_sumOfProbability;
public:
RandManager() :m_randomList(), m_sumOfProbability(0)
{
}
void AddRandomWord(RandomWord word)
{
if(m_sumOfProbability
实在不太想重新开Windows跟Visual Studio来编码
正好我也在练习C++ Template,那就很刚好试著用Template来实践一下
代码如下:
//
// main.cpp
// RandomTest
//
// Created by Cloud on 2011/4/10.
// Copyright 2011年 Orz. All rights reserved.
//
#include
#include
using namespace std;
template
class RandomWord
{
T m_Word;
int m_Probability;
public:
RandomWord(T word, int probability):m_Word(word),m_Probability(probability){}
T getWord() { return m_Word; }
int getProbability() { return m_Probability; }
};
template
class RandManager
{
vector m_randomList;
int m_sumOfProbability;
public:
RandManager() :m_randomList(), m_sumOfProbability(0)
{
}
void AddRandomWord(RandomWord word)
{
if(m_sumOfProbability