谁比较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 <stdio.h> #include <stdlib.h> 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)<f(b)) printf("<\n"); } return 0; }
//标准代码 #include <stdio.h> #include <stdlib.h> 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; }