-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCTDL085.cpp
More file actions
45 lines (44 loc) · 770 Bytes
/
Copy pathSCTDL085.cpp
File metadata and controls
45 lines (44 loc) · 770 Bytes
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
/**
* @file SCTDL085.cpp
* @author Long (you@domain.com)
* @brief BDN number is a number that only includes 0&1 meaningfully.
* Find the number of BDN numbers less than or equal to N
* @version 0.1
* @date 2023-06-10
*
* @copyright Copyright (c) 2023
*
*/
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
string n, k;
bool check(string s)
{
return s.size() < n.size() || (s.size() == n.size() && s <= n);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--)
{
int d = 0;
cin >> n;
stack<string> st;
st.push("1");
while (st.size())
{
k = st.top();
d++;
st.pop();
if (check(k + "0"))
st.push(k + "0");
if (check(k + "1"))
st.push(k + "1");
}
cout << d << endl;
}
}