谁比较2

Description

定义一个整数N中的2的指数为N二的级别,比如4=2^2则4的二度为2,6=2^1*a则6的二度为1

你的任务就是给出a,b中谁更2

Input

给出a,b 都是正数且不超过10000000

Output

给出a,b中谁更2

Sample Input

4 6
17 4
4 12

Sample Output

>
<
=
**Source** ****
#include 
#include 
int f(long a)
{
    int c = 0;
    while (a %2 == 0)
    {
        c++;
        a /= 2;
    }
    return c;
}

int main()
{
    int a,b;
    while ( 2 == scanf("%d%d",&a,&b))
    {
        if ( f(a)>f(b))
            printf(">\n");
        if (f(a)==f(b))
            printf("=\n");
        if (f(a)

//标准代码
#include 
#include 
int f(int n){
  int s = 0;
  while (n % 2 == 0)
    s++, n /= 2;
  return s;
}
int n, m;
void solve(){
  int flag = f(n) - f(m);
  if (flag > 0)
    puts(">");
  else if (flag == 0)
    puts("=");
  else
    puts("<"); } int main(){ while (~scanf("%d %d ", &n, &m)) solve(); return 0; }< pre>
坚持原创技术分享,您的支持将鼓励我继续创作!
  • 本文作者: Fayne
  • 本文链接: 399.html
  • 版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!