关注
import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Solution s = new Solution();
s.doBefore();
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int i = 0; i < t; i++) {
int n = sc.nextInt();
s.getResult(n);
}
sc.close();
}
}
class Solution {
public ArrayList<int[]> curResult = new ArrayList<int[]>();
// public boolean mark = false;
public void doBefore() {
int last = 0;
for(int i = 1; i <= 100000; i++) {
if(f(i) == g(i)) {
int[] arr = {i, ++last};
curResult.add(arr);
}
}
}
public void getResult(int n) {
int result = 1;
for(int i = 0; i < curResult.size(); i++) {
if(curResult.get(i)[0] <= n) {
result = curResult.get(i)[1];
} else
break;
}
System.out.println(result);
}
// int curMostClosed = 1;
// int result = 1; //当前结果是0;
//
// if (mark) {
// for (int k : curResult.keySet()) {
// if (k > curMostClosed && k <= n) {
// curMostClosed = k;
// }
// }
// result = curResult.get(curMostClosed);
// }
// mark = true;
//
// for(int i = curMostClosed + 1; i <= n; i++) {
// if(f(i) == g(i))
// result++;
// }
// curResult.put(n, result);
//
// System.out.println(result);
// }
private int f(int n ) {
int result = 0;
while(n != 0) {
result += n % 10;
n /= 10;
}
return result;
}
private int g(int n ) {
int result = 0;
while(n != 0) {
result += (n & 1) == 1 ? 1 : 0;
n >>>= 1;
}
return result;
}
}
查看原帖
点赞 评论
相关推荐
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客热帖
更多
正在热议
更多
# 我的实习收获 #
14469次浏览 282人参与
# 穿越回高考你还会选现在的专业吗 #
11176次浏览 162人参与
# 实习吐槽大会 #
17329次浏览 80人参与
# 我的租房踩坑经历 #
6745次浏览 118人参与
# 晒一晒你的工位 #
80912次浏览 287人参与
# 打工人锐评公司红黑榜 #
144530次浏览 892人参与
# 提前批过来人的忠告 #
102344次浏览 1114人参与
# 毕业旅行去哪玩儿 #
377次浏览 17人参与
# 非技术er求职现状 #
58223次浏览 428人参与
# 高学历就一定能找到好工作吗? #
47400次浏览 585人参与
# 运营/市场营销人的秋招现状 #
16641次浏览 186人参与
# 携程求职进展汇总 #
522728次浏览 3838人参与
# 你想对下半年说点什么 #
22424次浏览 209人参与
# 你投递的公司有几家约面了? #
104048次浏览 746人参与
# 工作压力大怎么缓解 #
78635次浏览 934人参与
# 运营人求职交流聚集地 #
133320次浏览 978人参与
# 你最满意的offer薪资是哪家公司? #
25574次浏览 132人参与
# 选完offer后,你后悔学机械吗? #
28971次浏览 160人参与
# 实习中的菜狗时刻 #
363102次浏览 3285人参与
# 今年形式下双非本找得到工作吗 #
139174次浏览 1062人参与