How resolve selection enigma code ?

Hi, great community

I'm on my way to learn c++, and thing are getting harder, that's why I need your help

I need to process some file that has this format (ID, label, duration, time). I had this CSV file that contains this data, there are thousands of lines
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
  	 6 , Lab7sec , 0 , 0:0:0 
	 17 , Lab7sec , 0 , 0:0:0 
	 24 , Lab7sec , 0 , 0:0:0 
	 30 , Lab7sec , 0 , 0:0:0 
	 237 , Lab2sec , 232 , 0:0:23
	 243 , Lab2sec , 232 , 0:0:23
	 256 , Lab2sec , 233 , 0:0:23
	 262 , Lab2sec , 233 , 0:0:23
	 274 , Lab2sec , 233 , 0:0:23
	 280 , Lab2sec , 233 , 0:0:23
	 286 , Lab2sec , 239 , 0:0:23
	 393 , Lab3sec , 379 , 0:0:37
	 406 , Lab3sec , 377 , 0:0:37
	 423 , Lab3sec , 379 , 0:0:37
	 440 , Lab3sec , 381 , 0:0:38
	 454 , Lab3sec , 380 , 0:0:38
	 466 , Lab3sec , 377 , 0:0:37
	 485 , Lab3sec , 381 , 0:0:38
	 498 , Lab3sec , 379 , 0:0:37
	 694 , Lab4sec , 680 , 0:1:8
	 709 , Lab4sec , 680 , 0:1:8
	 721 , Lab4sec , 677 , 0:1:7
	 736 , Lab4sec , 677 , 0:1:7
	 754 , Lab4sec , 680 , 0:1:8
	 769 , Lab4sec , 680 , 0:1:8
	 781 , Lab4sec , 677 , 0:1:7
	 797 , Lab4sec , 678 , 0:1:7
	 957 , Lab0sec , 904 , 0:1:30
	 976 , Lab0sec , 905 , 0:1:30
	 993 , Lab0sec , 904 , 0:1:30
	 1011 , Lab0sec , 904 , 0:1:30
	 1029 , Lab0sec , 904 , 0:1:30
	 1046 , Lab0sec , 903 , 0:1:30
	 1271 , Lab9sec , 1253 , 0:2:5
	 1284 , Lab9sec , 1247 , 0:2:4
	 1308 , Lab9sec , 1252 , 0:2:5
	 1322 , Lab9sec , 1247 , 0:2:4
	 1338 , Lab9sec , 1244 , 0:2:4
	 1365 , Lab9sec , 1252 , 0:2:5
	 1386 , Lab9sec , 1254 , 0:2:5
	 1400 , Lab9sec , 1249 , 0:2:4
	 1724 , Lab6sec , 1719 , 0:2:51
	 1729 , Lab6sec , 1718 , 0:2:51
	 1735 , Lab6sec , 1718 , 0:2:51
	 1742 , Lab6sec , 1719 , 0:2:51
	 1754 , Lab6sec , 1719 , 0:2:51
	 1760 , Lab6sec , 1719 , 0:2:51
	 1766 , Lab6sec , 1719 , 0:2:51
	 2041 , Lab6sec , 2036 , 0:3:23
	 2046 , Lab6sec , 2035 , 0:3:23
	 2052 , Lab6sec , 2035 , 0:3:23
	 3416 , Lab8sec , 3403 , 0:5:40
	 3444 , Lab8sec , 3403 , 0:5:40
	 3459 , Lab8sec , 3404 , 0:5:40
	 3472 , Lab8sec , 3403 , 0:5:40
	 3486 , Lab8sec , 3403 , 0:5:40
	 3500 , Lab8sec , 3403 , 0:5:40
	 3511 , Lab8sec , 3400 , 0:5:40
	 3896 , Lab5sec , 3891 , 0:6:29
	 3911 , Lab5sec , 3900 , 0:6:30
	 3917 , Lab5sec , 3900 , 0:6:30
	 3923 , Lab5sec , 3900 , 0:6:30
	 3929 , Lab5sec , 3900 , 0:6:30
	 3935 , Lab5sec , 3900 , 0:6:30
	 3941 , Lab5sec , 3900 , 0:6:30
	 3947 , Lab5sec , 3900 , 0:6:30
	 4118 , Lab1sec , 4085 , 0:6:48
	 4135 , Lab1sec , 4085 , 0:6:48
	 4144 , Lab1sec , 4009 , 0:6:40
	 4150 , Lab1sec , 4066 , 0:6:46
	 4181 , Lab1sec , 4080 , 0:6:48
	 4193 , Lab1sec , 4075 , 0:6:47
	 4209 , Lab1sec , 4074 , 0:6:47
	 4484 , Lab7sec , 4461 , 0:7:26
	 4495 , Lab7sec , 4460 , 0:7:26
	 4502 , Lab7sec , 4461 , 0:7:26
	 4508 , Lab7sec , 4461 , 0:7:26
	 4715 , Lab2sec , 4710 , 0:7:51
	 4721 , Lab2sec , 4710 , 0:7:51
	 4734 , Lab2sec , 4711 , 0:7:51
	 4740 , Lab2sec , 4711 , 0:7:51
	 4752 , Lab2sec , 4711 , 0:7:51
	 4758 , Lab2sec , 4711 , 0:7:51
	 4764 , Lab2sec , 4717 , 0:7:51


in fact, I'm interested in label and last part (time) to make a select, I'm not looking for kind of group by selection.

for example for the following part, the label Lab3sec I've to select the most repeated time, then choose the smallest duration, if I have smallest duration is repeated I have to select the first one. which is in this case (406 , Lab3sec , 377 , 0:0:37).
1
2
3
4
5
6
7
8
	 393 , Lab3sec , 379 , 0:0:37
	 406 , Lab3sec , 377 , 0:0:37
	 423 , Lab3sec , 379 , 0:0:37
	 440 , Lab3sec , 381 , 0:0:38
	 454 , Lab3sec , 380 , 0:0:38
	 466 , Lab3sec , 377 , 0:0:37
	 485 , Lab3sec , 381 , 0:0:38
	 498 , Lab3sec , 379 , 0:0:37


In case, of equality of repetition, I have to select the lowest time
here for Lab4sec 0:1:8 is repeated 4 times and 0:1:7 too, So I have to choose 0:1:7 with the smallest duration (721 , Lab4sec , 677 , 0:1:7).

1
2
3
4
5
6
7
8
	 694 , Lab4sec , 680 , 0:1:8
	 709 , Lab4sec , 680 , 0:1:8
	 721 , Lab4sec , 677 , 0:1:7
	 736 , Lab4sec , 677 , 0:1:7
	 754 , Lab4sec , 680 , 0:1:8
	 769 , Lab4sec , 680 , 0:1:8
	 781 , Lab4sec , 677 , 0:1:7
	 797 , Lab4sec , 678 , 0:1:7


the output I expect from the above csv file is:

1
2
3
4
5
6
7
8
9
10
11
12
  	 6 , Lab7sec , 0 , 0:0:0 
	 237 , Lab2sec , 232 , 0:0:23
	 406 , Lab3sec , 377 , 0:0:37
	 721 , Lab4sec , 677 , 0:1:7
	 1046 , Lab0sec , 903 , 0:1:30
         1338, Lab9sec, 1244, 0:2:4
	 1729 , Lab6sec , 1718 , 0:2:51
	 3511 , Lab8sec , 3400 , 0:5:40
         3896, Lab5sec, 3891, 0:6:29
	 4181 , Lab1sec , 4080 , 0:6:48
	 4495 , Lab7sec , 4460 , 0:7:26
	 4715 , Lab2sec , 4710 , 0:7:51


thank you in advance for your advice
Last edited on
Why are you doing this in C++?

If you're using Unix (or a Unix compatible) system, you'd use the standard system tools.
in fact, I'm not using Unix system or linux either.
Last edited on
Windows?
yes, but why not write a code? Actually, I want to do it and learn something new
put the file into your data structure, and also put in extra 'columns' or fields for the info you want, like duration. Anything simple that you can pre-compute, go ahead and do that and store it with the original data.

then its just a matter of locating what you want in the structure based off criteria. A sorted or sortable datastructure makes pulling off repeated values easy, but you need a stable-sort if you want to 'pick the first one from duplicates' or, as a trick, you can put in an original order column (first record is 0, second is 1, third is 2 ... etc) and do a sort by this then by that approach that retains the original ordering.

you can either make an object for each row, or you can just make a table where the fields are understood as 'columns' like a 2-d vector concept. The object lets you do more things, but I don't know if you need any of the doors it opens for you...
Last edited on
@jonnin okay I'll take your advice in consideration, I will post the code soon
this was a challenge for me as a beginner in C++.
I came up with this code

what do you think about it ?
is there any way to improve it ?
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <memory>
#include <functional>

using namespace std;

class FileCsv2Obj{
private:
    size_t id;
    string label;
    size_t duration;
    string time;
public:

    FileCsv2Obj(){}
    FileCsv2Obj(size_t id, string label, size_t duration, string time):
        id(id), label(label), duration(duration), time(time){}
    size_t getId() const
    { return id; }

    void setId(const size_t &value)
    { id = value; }

    string getLabel() const
    { return label; }

    void setLabel(const string &value)
    { label = value; }

    string getTime() const
    { return time; }

    void setTime(const string &value)
    { time = value; }

    size_t getDuration() const
    { return duration; }

    void setDuration(const size_t &value)
    { duration = value; }
    int getY() const;
    void setY(int value);
};

class sort_map{
public:
    string key;
    int val;
    sort_map(string key, int val):key(key), val(val){}
};

bool Sort_by(const sort_map& a ,const sort_map& b){
    return a.val > b.val;
}

stringstream proccess(vector<FileCsv2Obj> csvFile){
    string AdPrevFound = "";
    map<string,size_t> times;
    vector<FileCsv2Obj> retainer;
    vector<FileCsv2Obj> retainer2;
    vector< sort_map > v;
    stringstream FinalRsltBoby;
    FileCsv2Obj smallestOjb;
    int prevId;
    bool clearMap = false;
    for(vector<FileCsv2Obj>::size_type it = 0; it != csvFile.size(); it++){
        if(AdPrevFound != csvFile[it].getLabel() && !AdPrevFound.empty() || it == (csvFile.size() - 1)){
            cout << "=========== start showing \n";
            map<string,size_t>::iterator it;
            for ( it = times.begin(); it != times.end(); it++ ){
                std::cout << it->first
                          << " / "
                          << it->second
                          << std::endl ;
                v.push_back(sort_map(it->first, it->second));
            }
            sort(v.begin(),v.end(),Sort_by);
            vector< sort_map >::iterator itv;
            cout << "sorted" << endl;
            for (itv = v.begin(); itv != v.end(); ++itv){
                cout << (*itv).key << " - " << (*itv).val << endl;
            }
            smallestOjb = retainer.front();
            cout << "smallestOjb before "<< smallestOjb.getId()<<endl;
            for(vector<FileCsv2Obj>::iterator it = retainer.begin(); it != retainer.end(); it++){
                if((*it).getTime() == v.begin()->key){
                    if(smallestOjb.getDuration() > (*it).getDuration()){
                        smallestOjb = (*it);
                    }
                    retainer2.push_back((*it));
                }
            }
            cout << "smallestOjb after "<< smallestOjb.getId()<<endl;
            FinalRsltBoby << smallestOjb.getId()
                          <<", "<< smallestOjb.getLabel()
                          <<", "<< smallestOjb.getDuration()
                          <<", "<< smallestOjb.getTime() << "\n";
            cout << "=========== end showing \n";
            clearMap = true;
        }
        if(AdPrevFound != csvFile[it].getLabel() || AdPrevFound.empty()){
            cout << csvFile[it].getId() <<", "<<csvFile[it].getLabel()<<", "
                 << csvFile[it].getDuration() <<", "
                 << csvFile[it].getTime() << endl;
            if(times.count(csvFile[it].getTime())==0){
                times.insert(std::make_pair(csvFile[it].getTime(), 1));
                retainer.push_back(csvFile[it]);
            }
            if(clearMap){
                times.clear();
                retainer.clear();
                retainer2.clear();
                v.clear();
                clearMap = false;
                times.insert(std::make_pair(csvFile[it].getTime(), 1));
                retainer.push_back(csvFile[it]);
            }
        }

        else{
            cout <<"=>"<< csvFile[it].getId() <<", "<<csvFile[it].getLabel()<<", "
                 <<csvFile[it].getDuration()<<", "
                 <<csvFile[it].getTime()<< endl;
            if(times.count(csvFile[it].getTime())==0){
                times.insert(std::make_pair(csvFile[it].getTime(), 0));
                retainer.push_back(csvFile[it]);
                prevId = csvFile[it].getId();
            }
            if(times.count(csvFile[it].getTime())!=0){
                string time = csvFile[it].getTime();
                size_t val = times.find(time)->second;
                map<string,size_t>::iterator itMap = times.find(time);
                val++;
                if(itMap != times.end())
                    itMap->second = val;
                if(prevId != csvFile[it].getId()){
                    retainer.push_back(csvFile[it]);
                }
            }
        }
        AdPrevFound = csvFile[it].getLabel();
    }

    return FinalRsltBoby;
}


Last edited on
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
int main()
{
    std::vector<FileCsv2Obj> csvFile = {
        {6 , "Lab7sec" , 0 , "0:0:0"},
        {17 , "Lab7sec" , 0 , "0:0:0"},
        {24 , "Lab7sec" , 0 , "0:0:0"},
        {30 , "Lab7sec" , 0 , "0:0:0"},
        {237 , "Lab2sec" , 232 , "0:0:23"},
        {243 , "Lab2sec" , 232 , "0:0:23"},
        {256 , "Lab2sec" , 233 , "0:0:23"},
        {262 , "Lab2sec" , 233 , "0:0:23"},
        {274 , "Lab2sec" , 233 , "0:0:23"},
        {280 , "Lab2sec" , 233 , "0:0:23"},
        {286 , "Lab2sec" , 239 , "0:0:23"},
        {393 , "Lab3sec" , 379 , "0:0:37"},
        {406 , "Lab3sec" , 377 , "0:0:37"},
        {423 , "Lab3sec" , 379 , "0:0:37"},
        {440 , "Lab3sec" , 381 , "0:0:38"},
        {454 , "Lab3sec" , 380 , "0:0:38"},
        {466 , "Lab3sec" , 377 , "0:0:37"},
        {485 , "Lab3sec" , 381 , "0:0:38"},
        {498 , "Lab3sec" , 379 , "0:0:37"},
        {694 , "Lab4sec" , 680 , "0:1:8"},
        {709 , "Lab4sec" , 680 , "0:1:8"},
        {721 , "Lab4sec" , 677 , "0:1:7"},
        {736 , "Lab4sec" , 677 , "0:1:7"},
        {754 , "Lab4sec" , 680 , "0:1:8"},
        {769 , "Lab4sec" , 680 , "0:1:8"},
        {781 , "Lab4sec" , 677 , "0:1:7"},
        {797 , "Lab4sec" , 678 , "0:1:7"},
        {957 , "Lab0sec" , 904 , "0:1:30"},
        {976 , "Lab0sec" , 905 , "0:1:30"},
        {993 , "Lab0sec" , 904 , "0:1:30"},
        {1011 , "Lab0sec" , 904 , "0:1:30"},
        {1029 , "Lab0sec" , 904 , "0:1:30"},
        {1046 , "Lab0sec" , 903 , "0:1:30"},
        {1271 , "Lab9sec" , 1253 , "0:2:5"},
        {1284 , "Lab9sec" , 1247 , "0:2:4"},
        {1308 , "Lab9sec" , 1252 , "0:2:5"},
        {1322 , "Lab9sec" , 1247 , "0:2:4"},
        {1338 , "Lab9sec" , 1244 , "0:2:4"},
        {1365 , "Lab9sec" , 1252 , "0:2:5"},
        {1386 , "Lab9sec" , 1254 , "0:2:5"},
        {1400 , "Lab9sec" , 1249 , "0:2:4"},
        {1724 , "Lab6sec" , 1719 , "0:2:51"},
        {1729 , "Lab6sec" , 1718 , "0:2:51"},
        {1735 , "Lab6sec" , 1718 , "0:2:51"},
        {1742 , "Lab6sec" , 1719 , "0:2:51"},
        {1754 , "Lab6sec" , 1719 , "0:2:51"},
        {1760 , "Lab6sec" , 1719 , "0:2:51"},
        {1766 , "Lab6sec" , 1719 , "0:2:51"},
        {2041 , "Lab6sec" , 2036 , "0:3:23"},
        {2046 , "Lab6sec" , 2035 , "0:3:23"},
        {2052 , "Lab6sec" , 2035 , "0:3:23"},
        {3416 , "Lab8sec" , 3403 , "0:5:40"},
        {3444 , "Lab8sec" , 3403 , "0:5:40"},
        {3459 , "Lab8sec" , 3404 , "0:5:40"},
        {3472 , "Lab8sec" , 3403 , "0:5:40"},
        {3486 , "Lab8sec" , 3403 , "0:5:40"},
        {3500 , "Lab8sec" , 3403 , "0:5:40"},
        {3511 , "Lab8sec" , 3400 , "0:5:40"},
        {3896 , "Lab5sec" , 3891 , "0:6:29"},
        {3911 , "Lab5sec" , 3900 , "0:6:30"},
        {3917 , "Lab5sec" , 3900 , "0:6:30"},
        {3923 , "Lab5sec" , 3900 , "0:6:30"},
        {3929 , "Lab5sec" , 3900 , "0:6:30"},
        {3935 , "Lab5sec" , 3900 , "0:6:30"},
        {3941 , "Lab5sec" , 3900 , "0:6:30"},
        {3947 , "Lab5sec" , 3900 , "0:6:30"},
        {4118 , "Lab1sec" , 4085 , "0:6:48"},
        {4135 , "Lab1sec" , 4085 , "0:6:48"},
        {4144 , "Lab1sec" , 4009 , "0:6:40"},
        {4150 , "Lab1sec" , 4066 , "0:6:46"},
        {4181 , "Lab1sec" , 4080 , "0:6:48"},
        {4193 , "Lab1sec" , 4075 , "0:6:47"},
        {4209 , "Lab1sec" , 4074 , "0:6:47"},
        {4484 , "Lab7sec" , 4461 , "0:7:26"},
        {4495 , "Lab7sec" , 4460 , "0:7:26"},
        {4502 , "Lab7sec" , 4461 , "0:7:26"},
        {4508 , "Lab7sec" , 4461 , "0:7:26"},
        {4715 , "Lab2sec" , 4710 , "0:7:51"},
        {4721 , "Lab2sec" , 4710 , "0:7:51"},
        {4734 , "Lab2sec" , 4711 , "0:7:51"},
        {4740 , "Lab2sec" , 4711 , "0:7:51"},
        {4752 , "Lab2sec" , 4711 , "0:7:51"},
        {4758 , "Lab2sec" , 4711 , "0:7:51"},
        {4764 , "Lab2sec" , 4717 , "0:7:51"}
        };
    stringstream stm = proccess(csvFile);
    cout << "\nHello World!\n" << endl;
    cout << stm.str() << endl;
    return 0;
}
Last edited on
Replace function process() with following functions should be fine.

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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//class comparison for set using label
struct classveccomp {
  bool operator() (const FileCsv2Obj& lhs, const FileCsv2Obj& rhs) const
  { return lhs.getLabel() < rhs.getLabel(); }
};

//class comparison for set using id
struct classveccomp2 {
  bool operator() (const FileCsv2Obj& lhs, const FileCsv2Obj& rhs) const
  { return lhs.getId() < rhs.getId(); }
};

//helper function splits a string with delimeter and return a vector of string
vector<string> split(const string& str, const string& delim){
    vector<string> tokens;
    size_t prev = 0, pos = 0;
    do {
        pos = str.find(delim, prev);
        if (pos == string::npos) pos = str.length();
        string token = str.substr(prev, pos-prev);
        if (!token.empty()) tokens.push_back(token);
        prev = pos + delim.length();
    } while (pos < str.length() && prev < str.length());
    return tokens;
}

//helper function compares two time strings
int CompareTimeString(const string &lhs, const string &rhs){
    vector<string> t1 = split(lhs, ":"); 
    vector<string> t2 = split(rhs, ":"); 
    if(t1[0].compare(t2[0]) == 0){
        if(t1[1].compare(t2[1]) == 0)
            return t1[2].compare(t2[2]);
        else return t1[1].compare(t2[1]);
    }
    return t1[0].compare(t2[0]);
}
	
//helper function compares two FileCsv2Obj
int compareCsv(const FileCsv2Obj &lhs, const FileCsv2Obj &rhs){
    if(lhs.getDuration() == rhs.getDuration())
	    return CompareTimeString(lhs.getTime(), rhs.getTime());
	else return lhs.getDuration() - rhs.getDuration();
}

//main process is here
stringstream proccess(vector<FileCsv2Obj> csvFile){
    //create a set using label for ordering 
    set<FileCsv2Obj, classveccomp> setObj;
    pair<set<FileCsv2Obj, classveccomp>::iterator, bool> pairObj;
	
        //iterate through csvFile 
	for(auto it = csvFile.begin() ; it != csvFile.end(); ++it){
		pairObj = setObj.insert(*it);
		if(pairObj.second == false) {        //item found, cannot insert
			auto itSet = pairObj.first;      //point to element found
			if(compareCsv(*it, *itSet) < 0){ //replace, if new item lesser
				setObj.erase(itSet);
				setObj.insert(*it);
			}	
		}
	}
	
        //create new set using id for ordering
	set<FileCsv2Obj, classveccomp2> setObj2(setObj.begin(), setObj.end());
        //output to stringstream object
	stringstream ss;
	for(auto it = setObj2.begin() ; it != setObj2.end(); ++it){
		 ss << it->getId() << " " 
		    << it->getLabel() << " "
			<< it->getDuration() << " "
			<< it->getTime() << endl;
	}
	return ss;
}
Last edited on
thank you @homy18 I'm glad, you've take from your time to help me out thanks a lot

the problem with set containers they are containers that store unique elements
and I'have to accept duplication

you code is fine but it eliminates duplications

1
2
3
4
5
6
7
8
9
10
11
12
6, Lab7sec, 0, 0:0:0 <==
237, Lab2sec, 232, 0:0:23 <==
406, Lab3sec, 377, 0:0:37
721, Lab4sec, 677, 0:1:7
1046, Lab0sec, 903, 0:1:30
1338, Lab9sec, 1244, 0:2:4
1729, Lab6sec, 1718, 0:2:51
3511, Lab8sec, 3400, 0:5:40
3896, Lab5sec, 3891, 0:6:29
4181, Lab1sec, 4080, 0:6:48
4495, Lab7sec, 4460, 0:7:26 <==
4715, Lab2sec, 4710, 0:7:51 <==


cause lablel Lab7sec has two Ids and It might have more, that's what makes me struggling with this code.

your code remove them
1
2
3
4
5
6
7
8
9
10
6 Lab7sec 0 0:0:0
237 Lab2sec 232 0:0:23
406 Lab3sec 377 0:0:37
721 Lab4sec 677 0:1:7
1046 Lab0sec 903 0:1:30
1338 Lab9sec 1244 0:2:4
1729 Lab6sec 1718 0:2:51
3511 Lab8sec 3400 0:5:40
3896 Lab5sec 3891 0:6:29
4144 Lab1sec 4009 0:6:40
Last edited on
@yf007, you can modify easily struct classveccomp to use both label and id to compare within set or whatever you need. But I don't understand why you need duplication.
Last edited on
Okay, I will use both of them
I need duplication because each label has its own time, and I need to pick it up
Last edited on
OK. It's not Id but time stamp.

1
2
3
4
5
6
7
8
//class comparation for set using label
struct classveccomp {
  bool operator() (const FileCsv2Obj& lhs, const FileCsv2Obj& rhs) const
  { 

	return (lhs.getLabel() != rhs.getLabel())&&(lhs.getTime() < rhs.getTime() ); 
  }
};
wow Sir thanks
I noticed that the following line is not the most occurred

 
4144 Lab1sec 4009 0:6:40 occurred once


then

 
4181, Lab1sec, 4080, 0:6:48 occurred 3 times



your result is perfect except at label Lab1sec
Last edited on
Topic archived. No new replies allowed.