矢量的元素太多.组合程序

Too much elements of vector . Combinations program

本文关键字:组合 程序 太多 元素      更新时间:2023-10-16

大家好

我正在为乐透统计做一个项目,基本上它有类"kombinacije4",它具有第一个数字第二个数字第三个数字第四个数字的属性以及它上次出现的日期和时间以及组合出现的次数。

class kombinacije4 {
public:
    Date date;
    Time time;
    int first;
    int second;
    int third;
    int fourth;
    int howMuchRoundsDidntShowedUp;
    int howMuchTimesAppeared;
    void GetCombination(int, int, int, int);
    void GetCombinationsAfterRound(int);
};

然后我有这些元素的向量

std::vector<kombinacije4> fourties;

非常快速和很好地初始化了这个向量,但是当我想更改这些属性时,例如它上次出现的日期和时间或它出现的数量时,我遇到了问题,因为有 80 个数字,他们在一轮中绘制了 20 个数字。从这 20 个数字中,我必须将 4 个数字组合在一起,并在fourties中找到它们并更改它们的属性。七百次。因为有700发子弹。有没有人知道如何通过他们的值直接访问。也许std::find可以做点什么?显然我有时间限制问题。

以另一种方式做这个程序的任何想法?

for(auto i=round.begin();i!=round.end();i++){
        for(auto j=i+1;j!=round.end();j++){
            for(auto k=j+1;k!=round.end();k++){
                for(auto l=k+1;l!=round.end();l++){
                    for(auto p=fourties.begin();p!=fourties.end();p++){
                        -if-statement
                    }
                }
            }
        }
    }
  Obviously this block is going to pass 3 million times through the vector of million and half elements

谢谢!

要访问向量内对象的成员,您应该只使用 myobject[iterator].membername .

例如:

for (auto p = fourties.begin(); p!= fourties.end(); p++)
{
    if (fourties.at[p].first == "your data" && 
        fourties.at[p].second == "your data" && 
        fourties.at[p].third == "your data"  && 
        fourties.at[p].fourth == "your data")
    {
        fourties.at[p].date = 'your data';
        fourties.at[p].time = 'your data';
    }
}