NC25572. Number
描述
Bonnie得到了一个数字n。
现在她想对这个数字不断的做一种操作:
给定n,请问Bonnie需要做多少次操作?
输入描述
第一行一个数字--样例个数。
每个样例仅一行一个数字。
输出描述
每个样例输出一行一个数字—Bonnie需要做的操作次数。
示例1
输入:
6 9 99 2 11032 1000000000 62
输出:
2 3 9 44 9 13
说明:
第一个样例:C(clang 3.9) 解法, 执行用时: 141ms, 内存消耗: 1096K, 提交时间: 2019-05-04 20:08:53
#include<stdio.h> int main() { int a,n,c,t,m,f; scanf("%d",&m); while(m--){ c=0; scanf("%d",&n); while(n>1){ if(n%10==0) n/=10; else n++; c++; } printf("%d\n",c); } return 0; }
C++11(clang++ 3.9) 解法, 执行用时: 608ms, 内存消耗: 1276K, 提交时间: 2019-05-04 18:13:26
#include<iostream> using namespace std; int main(){ int T,n; cin>>T; while(T--){ cin>>n; int cnt=0; while(n>1){ while(n%10!=0) n++,cnt++; n=n/10;cnt++; } cout<<cnt<<endl; } }