-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLotteryTicket.cpp
More file actions
62 lines (54 loc) · 1.55 KB
/
LotteryTicket.cpp
File metadata and controls
62 lines (54 loc) · 1.55 KB
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
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include <string>
#include <sstream>
#include <climits>
#include<iomanip>
using namespace std;
string bingo(vector<pair<string, int>> ticket, int win) {
int count = 0;
for (auto& t : ticket)
{
for (char c : t.first)
{
if (c == t.second)
{
count++;
break;
}
}
}
return count >= win ? "Winner!" : "Loser!";
}
int main()
{
cout << bingo({ {"HGTYRE", 74}, {"BE", 66}, {"JKTY", 74} }, 3);
return 0;
}
/*Description:
Time to win the lottery!
Given a lottery ticket (ticket), represented by an array of 2-value arrays,
you must find out if you've won the jackpot.
Example ticket:
{ { "ABC", 65 }, { "HGR", 74 }, { "BYHT", 74 } }
To do this, you must first count the 'mini-wins' on your ticket. Each subarray has both a string and a number within it.
If the character code of any of the characters in the string matches the number, you get a mini win.
Note you can only have one mini win per sub array.
Once you have counted all of your mini wins, compare that number to the other input provided (win).
If your total is more than or equal to (win), return 'Winner!'. Else return 'Loser!'.
All inputs will be in the correct format. Strings on tickets are not always the same length.
Fundamentals
Strings
Arrays*/
// /> フ
// | n n 彡
// /`ミ_xノ
// / |
// / ヽ ノ
// │ | | |
// / ̄| | | |
// | ( ̄ヽ__ヽ_)__)
// \二つ
// ITS CAT FOR YOU