ACM 2453 Wrong Answer 我的输出结果正确,他却一直报错……DescriptionAs we known,data stored in the computers is in binary form.The problem we discuss now is about the positive integers and its binary form.Given a positive integer I,you
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/23 11:28:20
ACM 2453 Wrong Answer 我的输出结果正确,他却一直报错……DescriptionAs we known,data stored in the computers is in binary form.The problem we discuss now is about the positive integers and its binary form.Given a positive integer I,you
ACM 2453 Wrong Answer
我的输出结果正确,他却一直报错……
Description
As we known,data stored in the computers is in binary form.The problem we discuss now is about the positive integers and its binary form.
Given a positive integer I,you task is to find out an integer J,which is the minimum integer greater than I,and the number of '1's in whose binary form is the same as that in the binary form of I.
For example,if "78" is given,we can write out its binary form,"1001110".This binary form has 4 '1's.The minimum integer,which is greater than "1001110" and also contains 4 '1's,is "1010011",i.e."83",so you should output "83".
Input
One integer per line,which is I (1
ACM 2453 Wrong Answer 我的输出结果正确,他却一直报错……DescriptionAs we known,data stored in the computers is in binary form.The problem we discuss now is about the positive integers and its binary form.Given a positive integer I,you
#include
int Count_Num_One( int num )
{
\x05int counter_one = 0;
\x05while (num) {
\x05\x05if(num%2 == 1)
\x05\x05\x05counter_one++;
\x05\x05num = num /2;
\x05}
\x05return counter_one;
}
int main(void)
{
\x05int number,i;
\x05int counter = 0;
\x05int num_of_one = 0;
\x05
\x05while(scanf("%d",&number),number != 0)
\x05{
\x05\x05/*
\x05\x05if(number100000)
\x05\x05{
\x05\x05\x05continue;
\x05\x05}
\x05\x05*/
\x05\x05num_of_one = Count_Num_One(number);
\x05\x05for(number=number+1;;number++)
\x05\x05{
\x05\x05\x05if(Count_Num_One(number)==num_of_one)
\x05\x05\x05{
\x05\x05\x05\x05printf("%d\n",number);
\x05\x05\x05\x05break;
\x05\x05\x05}
\x05\x05}
\x05}
\x05return 0;
}