NC25108. [USACO 2006 Ope l]Round Numbers
描述
输入描述
Line 1: A single integer, N
输出描述
Line 1: Two space-separated integers: the number of trailing decimal zeros and the number of trailing binary zeros.
示例1
输入:
8000
输出:
3 6
说明:
The number is 8,000 decimal which is 1,1111,0100,0000 in cow-binary.C(clang 3.9) 解法, 执行用时: 2ms, 内存消耗: 372K, 提交时间: 2020-09-05 18:45:46
#include<stdio.h> int main() { int N,b=0,i=0,a; scanf("%d",&N); a=N; while(a%10==0){ a=a/10; i++; } printf("%d ",i); while(N%2==0){ b++; N=N/2; } printf("%d",b); }
Python3 解法, 执行用时: 17ms, 内存消耗: 2820K, 提交时间: 2021-05-19 15:11:29
n=int(input()) m=n ans1=ans2=0 while(n): if(n%10!=0): break n//=10 ans1+=1 while(m): if(m%2!=0): break m//=2 ans2+=1 print(ans1,ans2)
C++11(clang++ 3.9) 解法, 执行用时: 3ms, 内存消耗: 376K, 提交时间: 2020-09-05 18:20:20
#include<stdio.h> int main() { int N,i,j; scanf("%d",&N); for(i=0;N%10==0;i++) { N=N/10; } for(j=i;N%2==0;j++) { N=N/2; } printf("%d %d",i,j); }