hdu 2051 Bitset (java)

问题:

之前做过类似题,但这次仍然不能解决相关问题。

字符串倒过来输:StringBuffer str=new StringBuffer(s); s=str.reverse().toString()

Bitset

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 15548    Accepted Submission(s): 11804

Problem Description

Give you a number on base ten,you should output it on base two.(0 < n < 1000)

Input

For each case there is a postive number n on base ten, end of file.

Output

For each case output a number on base two.

Sample Input

1
2
3

Sample Output

1
10
11

代码:

import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner cin=new Scanner(System.in);
		while(cin.hasNext()){
			int n=cin.nextInt();
			String s="";
			while(n!=0){
				s=s+(n%2);
				n=n/2;
			}
			StringBuffer str=new StringBuffer(s);
			s=str.reverse().toString();
			System.out.println(str);
		}
	}
}
		
时间: 2024-11-08 21:07:50

hdu 2051 Bitset (java)的相关文章

hdu 1002大数(Java)

A + B Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 230395    Accepted Submission(s): 44208 Problem Description I have a very simple problem for you. Given two integers A and B, you

hdu 2052 Picture(java)

问题: 開始直接用输入的数作为宽和高,但实际上要多出两行边框,所以要加一个2. 还有题目要求最后要输出一个空行没有注意到. Picture Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 19789    Accepted Submission(s): 10178 Problem Description Give you the wid

hdu 2039 三角形 (java)

问题: 一个这么简单的问题交了几遍,我也是醉了,题目并没有说边都是整数,故不能有int型 三角形 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 57701    Accepted Submission(s): 19526 Problem Description 给定三条边,请你判断一下能不能组成一个三角形. Input 输入数据第一行

hdu 2040 亲和数 (java)

问题: 开始给for循环的J设置了小于根号a,导致约数没有全部得到. 亲和数 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 26302    Accepted Submission(s): 15814 Problem Description 古希腊数学家毕达哥拉斯在自然数研究中发现,220的所有真约数(即不是自身的约数)之和为: 1+

HDU 5047 Sawtooth (JAVA大数类)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 题面: Sawtooth Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 1636    Accepted Submission(s): 637 Problem Description Think about a plane: ● O

[ACM] hdu 1260 Tickets (动态规划)

Tickets Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submission(s) : 4   Accepted Submission(s) : 2 Font: Times New Roman | Verdana | Georgia Font Size: ← → Problem Description Jesus, what a great movie! Thou

hdu 4296 Buildings(贪心)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1822    Accepted Submission(s): 722 Problem Description Have you ever heard the sto

HDU 5826 physics(物理)

HDU 5826 physics(物理) Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)   Description 题目描述 There are n balls on a smooth horizontal straight track. The track can be considered to be a number line. The balls can be con

HDU 4832 Chess (DP)

Chess Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 24    Accepted Submission(s): 10 Problem Description 小度和小良最近又迷上了下棋.棋盘一共有N行M列,我们可以把左上角的格子定为(1,1),右下角的格子定为(N,M).在他们的规则中,"王"在棋盘上的走法遵循十字路线.