题解
[USACO2.4]分数化小数 Fractions to Decimals
1 条题解
-
0
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int n; cin >> n; int cnt = 0; for (int i = 1; i <= n; i++) { int x = i; bool f = true; while (x!=0) {//每个数拆位 int d = x % 10; if (d != 1 && d != 0){ f = false;//不符合要求 break; } x /= 10; } if (f==true){//符合条件 a[++cnt]=i;//标记符合条件的数 } } cout << cnt << "\n"; for(int i=1;i<=cnt;i++){ cout<<a[i]<<" ";//输出n以内符合条件的数 } return 0; }
- 1