-
Notifications
You must be signed in to change notification settings - Fork 77
/
solution.cpp
46 lines (42 loc) · 1.13 KB
/
solution.cpp
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
class Solution
{
public:
//计算一个整数中二进制1的个数
int numberOf1(int i)
{
int count = 0;
while (i)
{
count++;
i = (i - 1) & i;
}
return count;
}
vector<string> readBinaryWatch(int num)
{
int t = 0;
string q = to_string(t);
q += "0";
cout<<q<<endl;
vector<vector<string> > timeList;
for(int i=0;i<13;i++)
{
vector<string> temp;
timeList.push_back(temp);
}
for(int hour=0;hour<12;hour++)
{
int ledOfHour = numberOf1(hour);
for(int minute=0;minute<60;minute++)
{
int ledOfMinute = numberOf1(minute);
string minuteStr = to_string(minute);
if(minuteStr.size() == 1)
minuteStr = "0" + minuteStr;
string timeStr = to_string(hour) + ":" + minuteStr;
timeList[ledOfHour + ledOfMinute].push_back(timeStr);
}
}
return timeList[num];
}
};