[Euler]Problem 36 - Double-base palindromes
来源:互联网 发布:自学编程入门教材 编辑:程序博客网 时间:2024/06/05 01:54
The decimal number, 585 = 10010010012 (binary), is palindromic in both bases.
Find the sum of all numbers, less than one million, which are palindromic in base 10 and base 2.
(Please note that the palindromic number, in either base, may not include leading zeros.)
Brute Force!!!
public class Double_BasePalindromes {public static void main(String[] args) {long before = System.currentTimeMillis();new Double_BasePalindromes().calculate();System.out.println("elapsed time is : " + (System.currentTimeMillis() - before));}private void calculate() {String baseTwo = "";int sum = 0;for (int i = 1; i < 1000000; i++) {baseTwo = Integer.toBinaryString(i);if (isStringPalindromes(String.valueOf(i))) {if (isStringPalindromes(baseTwo)) {sum += i;}}}System.out.println("sum of all numbers is : " + sum);}private boolean isStringPalindromes(String str) {for (int i = 0; i <= str.length() / 2; i++) {if (str.charAt(i) != str.charAt(str.length() - 1 - i)) {return false;}}return true;}}
console :
sum of all numbers is : 872187elapsed time is : 133
- [Euler]Problem 36 - Double-base palindromes
- Project Euler:Problem 36 Double-base palindromes
- projecteuler---->problem=36----Double-base palindromes
- Problem 36 Double-base palindromes (二进制回文)
- 欧拉工程第36题:Double-base palindromes
- Project Euler Problem 36
- Project Euler problem 36
- project euler Problem 36
- project euler Problem 18 & 36
- Problem Euler
- NO_36_Double-base palindromes
- Problem 95 Prime Palindromes
- Euler Project Problem 6
- project euler problem 11
- Project Euler Problem 81
- Project Euler Problem 60
- Project Euler Problem 59
- Project Euler Problem 58
- 程序开发人员的思维导图
- 关于petitfatfs的移植问题
- 【转载】详解大端模式和小端模式
- 项目1任务二
- POJ 1936 ALL IN ALL 字符串
- [Euler]Problem 36 - Double-base palindromes
- hdu 4160 Dolls 匈牙利算法求最大匹配
- 杭电acm1003
- 结合硬件的发展史,谈谈你对计算机硬件发展趋势的看法?
- java面试题经典20例
- 黑马程序员_交通灯管理系统
- 【C#.NET】ASP.NET中实现页面间的参数传递 QueryString\Application\Session\Cookie
- Drawable Shape
- Webservice请求的使用方法