相鄰的1
題目描述
給定N 個正整數(shù) x ,判斷 X? 的二進制中是否有相鄰的1。例如 1011, 表示有相鄰的1.
(1<=n<=1000)
輸入
輸入格式:
? ? ?第一行一個整數(shù)N,第二行N個正整數(shù)。
輸出
N行,”yes“? ?表示有相鄰的1 ,“no"表示 沒有
樣例輸入?復制
1
3
樣例輸出?復制
yes
#include <iostream>
using
namespace
std;
int
main()
{
????
int
N,x;
????
cin>>N;
????
for
(
int
i=1;i<=N;i++)
????
{
????????
cin>>x;
????????
bool
ans=
false
;
????????
bool
is=
false
;
????????
while
(x!=0)
????????
{
????????????
if
(x%2==1)
????????????
{
????????????????
if
(ans==
true
)
????????????????
{
????????????????????
cout<<
"yes"
<<endl;
????????????????????
is=
true
;
????????????????????
break
;
????????????????
}
????????????????
else
????????????????????
ans=
true
;
????????????
}
????????????
else
????????????????
ans=
false
;
????????????
x/=2;
????????
}
????????
if
(!is)
????????????
cout<<
"no"
<<endl;
????
}
????
return
0;
}
標簽: