how to add different numbers?

Hi, Im a beginner and I'm stuck now with one function. It's hard to explain shortly, but I would really appreciate your help. I can't come up with a function that could add only different numbers. The task asks to find how many days people didnt visit the shop. To make it sound easier, I'll show you an example of entering the data:
1
2
3
4
5
  cin>>n;//number off people
  for(int i=0; i<n; i++)
   cin>>d; //days that person went to the shop
   for(int j=0;  j<d; j++)
    cin>>A[j];//the exact days 

So for example n=2 (so two people only), then one went 3 days and days 12, 5, 3, the other went only 1 day and day 12. So that means, the shop didnt had customers for 28 days(I take 31 days), as both went on day 12 (repeats). I know I explained it hardly, but I really need help and would appreciate it :)
1
2
3
4
5
6
7
8
9
10
11
12
13
# include <bitset>
# include <iostream>

int main() {
  std::bitset<31> days;
  
  // if someone visits on day n, set days[n] to true.  
  for (unsigned day_visited; std::cin >> day_visited; )
    if (day_visited <= days.size()) days.set(day_visited);

  // The number of days with no visitors is given by the number of unset bits.
  std::cout << (~days).count() << '\n'; 
}


Live demo:
http://coliru.stacked-crooked.com/a/0efddf81775f3404
Last edited on
Topic archived. No new replies allowed.