私信TA

用户名:Praguetramp

访问量:29498

签 名:

等  级
排  名 19
经  验 19963
参赛次数 0
文章发表 130
年  龄 0
在职情况 待业
学  校
专  业

  自我简介:

aura

解题思路:      字符串与2进制
    
注意事项:       内码的32位的表示

参考代码:

import java.math.BigInteger;
import java.util.Scanner;

public class Main {
	

	public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int cnt=0;
        while(in.hasNext()) {
        	BigInteger n =in.nextBigInteger();
        	String tmp =n.toString(2);  //转化为2进制串
        	int len=tmp.length();
        	if(tmp.length()<32) {
        		for(int i=1;i<=32-len;i++)
        			tmp="0"+tmp;     //转化为32位内码
        	}
        	String rev =new StringBuffer(tmp).reverse().toString();
        	if(tmp.equals(rev))
        		cnt++;
        }
    	System.out.println(cnt);
        in.close();
    }
}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区